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

Re: Fixed highlighting in draft mode



At Tue, 19 Jan 2010 11:32:36 -0500,
David Abrahams wrote:
> 
> > How about such hack?
> > 
> > (defun my-highlight-hook (beg end len)
> >   (let ((begining (save-excursion
> > 		    (goto-char beg)
> > 		    (re-search-backward "^" nil t)))
> > 	(ending (save-excursion
> > 		  (goto-char end)
> > 		  (re-search-forward "$" nil t))))
> >     (put-text-property begining ending 'face nil)
> >     (wl-highlight-message begining ending t nil)
> >     (wl-highlight-message begining ending t t)))
> > 
> > (add-hook 'wl-draft-mode-hook (lambda ()
> > 				(add-hook 'after-change-functions
> > 					  'my-highlight-hook)))
> 
> 
> Well, I fixed my hack w.r.t delete-selection-mode; all I needed to do
> was to add:
> 
>   (put 'wl-draft-newline 'delete-selection t)
> 
> but frankly I like your hack better, if it works.  I'll test it.

Hi Vitaly,

Test report and a few questions.

With just your hack, I can reliably hang emacs as follows:

1. enter a Summary buffer
2. on a message, hit RET
3. `w' to start writing a new message
4. Fill out the To: and Subject: fields
5. `C-c C-c'
6. Back in the Summary buffer, hit `D'

The reasons are completely mysterious to me.  I can get rid of the
hang by un-hooking draft-mode both in the send hook *and* in
wl-draft-generate-clone-buffer as follows:

(defun my-wl-highlight-hook (beg end len)
  (let ((beginning (save-excursion
		    (goto-char beg)
		    (re-search-backward "^" nil t)))
	(ending (save-excursion
		  (goto-char end)
		  (re-search-forward "$" nil t))))
    (put-text-property beginning ending 'face nil)
    (wl-highlight-message beginning ending t nil)
    (wl-highlight-message beginning ending t t)
    ))

(defun my-wl-draft-install-change-hooks ()
  (add-hook 'after-change-functions 'my-wl-highlight-hook))

(defun my-wl-draft-remove-change-hooks ()
  (remove-hook 'after-change-functions 'my-wl-highlight-hook))

(add-hook 'wl-draft-mode-hook 'my-wl-draft-install-change-hooks)
(add-hook 'wl-draft-send-hook 'my-wl-draft-remove-change-hooks)

(defadvice wl-draft-generate-clone-buffer (around wl-draft-disable-highlight preactivate)
   (remove-hook 'wl-draft-mode-hook 'my-wl-draft-install-change-hooks)
   ad-do-it
   (add-hook 'wl-draft-mode-hook 'my-wl-draft-install-change-hooks))

Questions:

1. Why are two calls to wl-highlight-message needed?  Removing one
   does indeed break highlighting again, but it's a mystery to me.  It
   seems like the first call, with `body-only' set to `nil', should be
   enough.

2. Is there a good reason to use re-search-forward/backward instead of
   beginning/end-of-line?

Thanks for your help!

-- 
Dave Abrahams           Meet me at BoostCon: http://www.boostcon.com
BoostPro Computing
http://www.boostpro.com