eev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[eev] eeindirect


From: rubikitch
Subject: [eev] eeindirect
Date: Mon, 23 Jan 2006 06:46:45 +0900 (JST)

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/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]