[Top][All Lists]

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

Re: Edit region in different mode

From: Kevin Rodgers
Subject: Re: Edit region in different mode
Date: Thu, 23 Dec 2004 10:01:01 -0700
User-agent: Mozilla Thunderbird 0.9 (X11/20041105)

Oliver Scholz wrote:
> I use the following to write Emacs Lisp in my usenet postings:
> (defun egoge-write-elisp ()
>   (interactive)
>   (if (not (eq major-mode 'message-mode))
>       (message "Not a message buffer.")
>     (switch-to-buffer (make-indirect-buffer (current-buffer)
>                                        "*emacs-lisp-message*"))
>     (emacs-lisp-mode)))
> I guess, this could serve as a starter for you.

It's an excellent start.  Here's what I've come up with, based on that:

(defun edit-region (&optional edit-mode)
  "Edit the current region in a separate buffer.
With a prefix arg, change `major-mode' to EDIT-MODE."
  (interactive (list (if current-prefix-arg
(intern (completing-read (format "Major mode (%s): "
                                                  t nil nil
(symbol-name major-mode))))))
  (clone-indirect-buffer nil t)
  (narrow-to-region (region-beginning) (region-end))
  (when edit-mode
    (funcall edit-mode)))

(defun major-mode-p (symbol)
  "Return non-nil if SYMBOL is a major mode."
  (and (fboundp symbol)
       (let ((function-name (symbol-name symbol)))
         (and (string-match "-mode\\'" function-name)
(not (string-match "\\`turn-\\(on\\|off\\)-" function-name))))
       (not (assq symbol minor-mode-alist))))

Kevin Rodgers

reply via email to

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