Gnus development mailing list
 help / color / mirror / Atom feed
From: Daniel Pittman <daniel@rimspace.net>
Subject: Re: Q: Use external editor for Gnus?
Date: Tue, 23 Oct 2001 18:52:51 +1000	[thread overview]
Message-ID: <874roqu49o.fsf@inanna.rimspace.net> (raw)
In-Reply-To: <vafpu7elqpq.fsf@INBOX.auto.gnus.tok.lucy.cs.uni-dortmund.de> (Kai.Grossjohann@CS.Uni-Dortmund.DE's message of "Tue, 23 Oct 2001 10:12:49 +0200")

[-- Attachment #1: Type: text/plain, Size: 1351 bytes --]

On Tue, 23 Oct 2001, Kai Großjohann wrote:
> Daniel Pittman <daniel@rimspace.net> writes:
> 
>> Presumably you could write your own message mode hook that would
>> invoke the external editor and stuff. But ... why?
> 
> They say, they're so accustomed to vim keybindings, they don't want to
> switch.  And actually, I can understand this.  I'm equally addicted to
> Emacs keybindings, after all!
> 
> Now, if they were addicted to vi keybindings, we could just tell them
> to use viper.  But with vim keybindings?

Mostly the same, I believe. Anyway, in /theory/ you could do something
like the attached Lisp, but it's pretty horrible.

Oh, and untested, though I am almost tempted just to see how insane a
thing I could put together. :)

The code, as written, probably falls over in the following cases:
1. User kills the message buffer before the editor terminates.
2. Editor terminates uncleanly on startup.
3. Editor is canceled with no changes.
4. Multiple message buffers all at once.

You could probably solve most of the issues, including the lack of
closures, by making the code use buffer local values in the *message*
buffer to store state.


Heh. You know, I /must/ really want to avoid this mailing list setup I
have to do. I would never have written something this silly otherwise. ;)

        Daniel


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-emacs-lisp, Size: 1138 bytes --]

(defun edit-buffer-in-vi ()
  "Put the content of the buffer into an external file and invoke VI on it."
  (let ((filename (make-temp-name "silly.vi.user."))
	(message  (current-buffer)))
    (with-temp-buffer filename
		      (insert (buffer-string message)))
    (let ((editor (start-process-shell-command "message editor"
					       nil ; no associated buffer...
					       "xterm"
					       "-e"
					       "vim"
					       filename)))
      (cons editor filename))))

(defun edit-buffer-in-vi-make-closure (buffer filename)
  "Restore the content of buffer from filename when invoked."
  (let ((buffer-name (buffer-name buffer))) ; Oh for closures...
    `(lambda ()
      (let ((buffer (get-buffer ,buffer-name)))
	(when buffer
	  (with-current-buffer buffer
	    (erase-buffer)
	    (insert-file-contents ,filename)))))))
  
(add-hook 'message-setup-hook		; am I the right hook?
	  (lambda ()
	    "Invoke an external editor on the content of this buffer..."
	    (let ((result (edit-buffer-in-vi)))
	      (set-process-sentinel
	       (car result)
	       (edit-buffer-in-vi-make-closure (current-buffer) (cdr result))))))

[-- Attachment #3: Type: text/plain, Size: 149 bytes --]


-- 
Unix was not designed to stop people from doing stupid things,
because that would also stop them from doing clever things.
        -- Doug Gwyn

  reply	other threads:[~2001-10-23  8:52 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-10-22 21:07 Kai Großjohann
2001-10-23  2:44 ` Daniel Pittman
2001-10-23  8:12   ` Kai Großjohann
2001-10-23  8:52     ` Daniel Pittman [this message]
2001-10-27 22:49       ` Florian Weimer
2001-10-28  9:37         ` Daniel Pittman
2001-10-23 13:53     ` Samuel Padgett
2001-10-23 15:03       ` Kai Großjohann
2001-10-24  2:30         ` Samuel Padgett

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874roqu49o.fsf@inanna.rimspace.net \
    --to=daniel@rimspace.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).