[Top][All Lists]

[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)


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 "";)

(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*"))
         (if (not indirect-mode-name)
             (setq indirect-mode-name
                     "Mode: "
                     (mapcar (lambda (e)
                               (list (symbol-name e)))
                             (apropos-internal "-mode$" 'commandp))
                     nil t)))
    (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."
  (let ((eebound-re "^[-;%#]+\n")      ; bounded region delimiter regexp
        s e)
      (when (re-search-backward eebound-re nil t)
        (forward-line -1)
        (setq s (point))))
      (when (and s (re-search-forward eebound-re nil t))
        (setq e (point))
        (indirect-region s e)))))

reply via email to

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