[Top][All Lists]

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

Re: Edit region in different mode

From: Albert Reiner
Subject: Re: Edit region in different mode
Date: 23 Dec 2004 18:42:47 +0100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3

Thanks to all of you for your help!

However, most of the solutions do not seem to work here; the only
exception is Pascal's

[Pascal Bourguignon <address@hidden>, 22 Dec 2004 20:51:07 +0100]:
> I'd do narrow-to-region and xyz-mode
> then widden and original-mode

(Without the initial narrow-to-region, BTW, noweb-mode simply
overrides the mode change.)

All the others have some problem as they are:

[Pascal Bourguignon <address@hidden>, 22 Dec 2004 20:51:07 +0100]:
> Yes, I have the same problem. Here's what I have in my ~/.emacs:
> (global-set-key [f5]       'set-justification-left)
> (global-set-key [3 f5]    (lambda (start end) (interactive "r") 
>                               (let ((mode major-mode))
>                                 (text-mode)
>                                 (set-justification-left start end)
>                                 (funcall mode))))

Here C-c f5 ends up re-indenting things even before the beginning of
region, presumably because there is no initial blank line (and just
adding such a line does not work well with the noweb file format).

[Mathias Dahl <address@hidden>, 23 Dec 2004 13:17:20 +0100]:
> (fset 'edit-region-in-tempo
>    [?\M-w ?\C-x ?b ?t ?e ?m ?p ?o ?\C-m ?\C-y ?\M-x ?t ?e ?x ?t ?  ?m ?o ?d 
> ?e ?\C-m])
> (fset 'edit-region-in-tempo-go-back
>    [C-home ?\C-  C-end ?\M-w ?\C-x ?k return ?\M-x ?d ?e ?l ?e ?t ?e ?  ?r ?e 
> ?g tab return ?\C-y])

As it stands, edit-region-in-tempo-go-back runs into an error when
killing the buffer but I suppose that could be fixed easily.  Ideally,
however, it should not depend on there being no editing in other
buffers in between, which probably requires re-writing in elisp.

[Oliver Scholz <address@hidden>, Thu, 23 Dec 2004 13:52:42 +0100]:
> (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)))

(BTW - egoge wouldn't be some classical Greek: )EGW/ GE, would it?)

[Kevin Rodgers <address@hidden>, Thu, 23 Dec 2004 10:01:01 -0700]:
> (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))))

Both Oliver's and Kevin's solutions run into the same problem: Somehow
noweb-mode keeps interfering in the indentation, which leads to rather
bizarre results.

In the light of Oliver's comment:

[Oliver Scholz <address@hidden>, Thu, 23 Dec 2004 13:52:42 +0100]:
> However, I do believe that mmm-mode would provide a more elegant
> solution. I never really used it, but the last time I checked I was
> not forced at all to use some tags, but IIRC I just issued a command
> on a region and then for text in that region Emacs behaved as if a
> different major mode were active, an effect that was lost once I
> revisited the file.

I will have another look at mmm-mode first; there even seems to be an
mmm-noweb-mode.  If that does not work out I will try to come up with
something along the lines of Mathias' macros.

Thanks again for all your help,


reply via email to

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