Home
Reading
Searching
Subscribe
Sponsors
Statistics
Posting
Contact
Spam
Lists
Links
About
Hosting
Filtering
Features Download
Marketing
Archives
FAQ
Blog
 
Gmane
From: rubikitch <rubikitch-X+L+6nJQZ58h9ZMKESR00Q <at> public.gmane.org>
Subject: eeindirect
Newsgroups: gmane.emacs.eev.devel
Date: Sunday 22nd January 2006 21:46:45 UTC (over 12 years ago)
Hi,

I found some useful code in the EmacsWiki.
And I hacked up `eeindirect' to edit bounded regions in e-scripts.
Type `M-x eeindirect' in the bounded region and set your favorite
major-mode.
This elisp will help us to write e-scripts smoothly.

# (find-w3m "http://www.emacswiki.org/cgi-bin/wiki/IndirectBuffers")

(defvar indirect-mode-name nil
  "Mode to set for indirect buffers.")
(make-variable-buffer-local 'indirect-mode-name)

(defun indirect-region (start end)
  "Edit the current region in another buffer.
    If the buffer-local variable `indirect-mode-name' is not set, prompt
    for mode name to choose for the indirect buffer interactively.
    Otherwise, use the value of said variable as argument to a funcall."
  (interactive "r")
  (let ((buffer-name (generate-new-buffer-name "*indirect*"))
        (mode
         (if (not indirect-mode-name)
             (setq indirect-mode-name
                   (intern
                    (completing-read
                     "Mode: "
                     (mapcar (lambda (e)
                               (list (symbol-name e)))
                             (apropos-internal "-mode$" 'commandp))
                     nil t)))
           indirect-mode-name)))
    (switch-to-buffer (make-indirect-buffer (current-buffer) buffer-name))
    (narrow-to-region start end)
    (funcall mode)
    (goto-char (point-min))
    ))

(defun eeindirect ()
  "Edit the eev bounded region in another buffer."
  (interactive)
  (let ((eebound-re "^[-;%#]+\n")      ; bounded region delimiter regexp
        s e)
    (save-excursion
      (when (re-search-backward eebound-re nil t)
        (forward-line -1)
        (setq s (point))))
    (save-excursion
      (when (and s (re-search-forward eebound-re nil t))
        (beginning-of-line)
        (setq e (point))
        (indirect-region s e)))))
--
rubikitch
http://www.rubyist.net/~rubikitch/
 
CD: 3ms