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

Re: Draft cursor position



At Tue, 13 Apr 2010 16:58:57 +0100,
Richard Lewis wrote:
> 
> Is there a hook in wl which gets called when, in draft-mode, the
> cursor moves above or below the "--text follows this line--" marker?
> 
Nevermind, I've written my own:

(defvar rjl/wl-draft-enter-headers-hook nil
  "A hook called when the cursor enters the headers section of a
  message draft.")

(defvar rjl/wl-draft-enter-body-hook nil
  "A hook called when the cursor enters the body of a message
  draft.")

(defvar rjl/wl-draft-current-cursor-position nil
  "Stores whether the cursor in a wl-draft-mode buffer is
  currently in the headers or the body.")

(defconst rjl/wl-draft-body-marker "--text follows this line--")

(defadvice next-line (before wl-draft-next-line-after-body-marker disable)
  (save-excursion
    (beginning-of-line)
    (if (looking-at-p rjl/wl-draft-body-marker)
	(progn
	  (setq rjl/wl-draft-current-cursor-position 'body)
	  (run-hooks 'rjl/wl-draft-enter-body-hook)))))

(defadvice previous-line (before wl-draft-previous-line-before-body-marker disable)
  (save-excursion
    (beginning-of-line)
    (if (looking-at-p rjl/wl-draft-body-marker)
	(progn
	  (setq rjl/wl-draft-current-cursor-position 'headers)
	  (run-hooks 'rjl/wl-draft-enter-headers-hook)))))

; also advise other movement functions: scroll

(add-hook 'wl-draft-mode-hook
	  (lambda ()
	    (ad-enable-advice 'next-line 'before 'wl-draft-next-line-after-body-marker)
	    (ad-enable-advice 'previous-line 'before 'wl-draft-previous-line-before-body-marker)
	    (ad-activate 'next-line)
	    (ad-activate 'previous-line)))

(add-hook 'wl-draft-kill-pre-hook
	  (lambda ()
	    (setq rjl/wl-draft-current-cursor-position nil)
	    (ad-disable-advice 'next-line 'before 'wl-draft-next-line-after-body-marker)
	    (ad-disable-advice 'previous-line 'before 'wl-draft-previous-line-before-body-marker)
	    (ad-activate 'next-line)
	    (ad-activate 'previous-line)))

; also add-hook 'wl-draft-send-hook ?

> I'd like to be able to execute a function when the cursor is moved
> into the body of a draft message.

So now I can do this:

(add-hook 'rjl/wl-draft-enter-headers-hook
	  (lambda ()
	    (flyspell-mode-off)))

(add-hook 'rjl/wl-draft-enter-body-hook
	  (lambda ()
	    (flyspell-mode)))

I expect there's probably an existing solution to this.

Basically, all I was trying to achieve was to be able to enable
flyspell-mode when in the body of a wl-draft-mode buffer, and disable
it when I'm in the headers section. This prevents flyspell-mode from
clobbering the bbdb completion keybinding.
-- 
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Richard Lewis
ISMS, Computing
Goldsmiths, University of London
Tel: +44 (0)20 7078 5134
Skype: richardjlewis
JID: ironchicken@jabber.earth.li
http://www.richard-lewis.me.uk/
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
+----------------------------------------------+
| Support open access to scholarship           |
| http://freeculture.org/ http://www.doaj.org/ |
+----------------------------------------------+