From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Kevin Rodgers Newsgroups: gmane.emacs.help Subject: Re: Edit region in different mode Date: Thu, 23 Dec 2004 10:01:01 -0700 Message-ID: <330buiF3rjdoaU1@individual.net> References: <87fz1x6usl.fsf@ID-87814.user.uni-berlin.de> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1103821465 15597 80.91.229.6 (23 Dec 2004 17:04:25 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 23 Dec 2004 17:04:25 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Dec 23 18:04:20 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1ChWNw-0005s1-00 for ; Thu, 23 Dec 2004 18:04:20 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1ChWYX-0005Qf-SB for geh-help-gnu-emacs@m.gmane.org; Thu, 23 Dec 2004 12:15:17 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 45 Original-X-Trace: individual.net YO4r8xmDcOpontW7cr1ejQtwCe+O3Vg9KiSY+mjgx10p6Pgbo= User-Agent: Mozilla Thunderbird 0.9 (X11/20041105) X-Accept-Language: en-us, en In-Reply-To: <87fz1x6usl.fsf@ID-87814.user.uni-berlin.de> Original-Xref: shelby.stanford.edu gnu.emacs.help:127494 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:22951 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:22951 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): " major-mode) obarray 'major-mode-p t nil nil (symbol-name major-mode)))))) (clone-indirect-buffer nil t) (narrow-to-region (region-beginning) (region-end)) (shrink-window-if-larger-than-buffer) (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