all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* jit-lock simplification?
@ 2006-09-13 12:25 Kim F. Storm
  2006-09-13 13:03 ` Stefan Monnier
  0 siblings, 1 reply; 7+ messages in thread
From: Kim F. Storm @ 2006-09-13 12:25 UTC (permalink / raw)



I was debugging a timer problem, and noticed some very odd lambda
forms in the timer-list.  It turns out to be the lambda generated by
the jit-lock code below.

Wouldn't it work just as well with the following patch?


*** jit-lock.el	25 Aug 2006 08:57:52 +0200	1.55
--- jit-lock.el	13 Sep 2006 14:12:18 +0200	
***************
*** 397,415 ****
             ;; eagerly extend the refontified region with
             ;; jit-lock-after-change-extend-region-functions.
             (when (< start orig-start)
!              (lexical-let ((start start)
!                            (orig-start orig-start)
!                            (buf (current-buffer)))
!                (run-with-timer
!                 0 nil (lambda ()
!                         (with-current-buffer buf
!                           (with-buffer-prepared-for-jit-lock
!                               (put-text-property start orig-start
!                                                  'fontified t)))))))
  
  	   ;; Find the start of the next chunk, if any.
  	   (setq start (text-property-any next end 'fontified nil))))))))
  
  \f
  ;;; Stealth fontification.
  
--- 397,415 ----
             ;; eagerly extend the refontified region with
             ;; jit-lock-after-change-extend-region-functions.
             (when (< start orig-start)
! 	     (run-with-timer 0 nil 'jit-lock-fontify-again
! 			     (current-buffer) start orig-start))
  
  	   ;; Find the start of the next chunk, if any.
  	   (setq start (text-property-any next end 'fontified nil))))))))
  
+ (defun jit-lock-fontify-again (buf start end)
+   "Fontify in buffer BUF from START to END."
+   (with-current-buffer buf
+     (with-buffer-prepared-for-jit-lock
+      (put-text-property start end 'fontified t))))
+ 
+ 
  \f
  ;;; Stealth fontification.
  

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: jit-lock simplification?
  2006-09-13 12:25 jit-lock simplification? Kim F. Storm
@ 2006-09-13 13:03 ` Stefan Monnier
  2006-09-13 13:31   ` David Kastrup
  2006-09-13 13:49   ` Kim F. Storm
  0 siblings, 2 replies; 7+ messages in thread
From: Stefan Monnier @ 2006-09-13 13:03 UTC (permalink / raw)
  Cc: emacs-devel

> I was debugging a timer problem, and noticed some very odd lambda
> forms in the timer-list.  It turns out to be the lambda generated by
> the jit-lock code below.

> Wouldn't it work just as well with the following patch?

I see no reason why it shouldn't work as well.
I just find it less elegant ;-)


        Stefan


> *** jit-lock.el	25 Aug 2006 08:57:52 +0200	1.55
> --- jit-lock.el	13 Sep 2006 14:12:18 +0200	
> ***************
> *** 397,415 ****
>              ;; eagerly extend the refontified region with
>              ;; jit-lock-after-change-extend-region-functions.
>              (when (< start orig-start)
> !              (lexical-let ((start start)
> !                            (orig-start orig-start)
> !                            (buf (current-buffer)))
> !                (run-with-timer
> !                 0 nil (lambda ()
> !                         (with-current-buffer buf
> !                           (with-buffer-prepared-for-jit-lock
> !                               (put-text-property start orig-start
> !                                                  'fontified t)))))))
  
>   	   ;; Find the start of the next chunk, if any.
>   	   (setq start (text-property-any next end 'fontified nil))))))))
  
>   \f
>   ;;; Stealth fontification.
  
> --- 397,415 ----
>              ;; eagerly extend the refontified region with
>              ;; jit-lock-after-change-extend-region-functions.
>              (when (< start orig-start)
> ! 	     (run-with-timer 0 nil 'jit-lock-fontify-again
> ! 			     (current-buffer) start orig-start))
  
>   	   ;; Find the start of the next chunk, if any.
>   	   (setq start (text-property-any next end 'fontified nil))))))))
  
> + (defun jit-lock-fontify-again (buf start end)
> +   "Fontify in buffer BUF from START to END."
> +   (with-current-buffer buf
> +     (with-buffer-prepared-for-jit-lock
> +      (put-text-property start end 'fontified t))))
> + 
> + 
>   \f
>   ;;; Stealth fontification.
  

> -- 
> Kim F. Storm <storm@cua.dk> http://www.cua.dk



> _______________________________________________
> Emacs-devel mailing list
> Emacs-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: jit-lock simplification?
  2006-09-13 13:03 ` Stefan Monnier
@ 2006-09-13 13:31   ` David Kastrup
  2006-09-13 14:43     ` Stefan Monnier
  2006-09-13 13:49   ` Kim F. Storm
  1 sibling, 1 reply; 7+ messages in thread
From: David Kastrup @ 2006-09-13 13:31 UTC (permalink / raw)
  Cc: emacs-devel, Kim F. Storm

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> I was debugging a timer problem, and noticed some very odd lambda
>> forms in the timer-list.  It turns out to be the lambda generated by
>> the jit-lock code below.
>
>> Wouldn't it work just as well with the following patch?
>
> I see no reason why it shouldn't work as well.
> I just find it less elegant ;-)

Disagree.  If `run-with-timer' has the possibility of passing values,
that should be preferred over `lexical-let'.  Whether one wants to use
a named or an anonymous lambda function is, in contrast, more a matter
of taste.

If this were Scheme, using a closure would more or less be natural,
but in Emacs Lisp, this is just ugly.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: jit-lock simplification?
  2006-09-13 13:03 ` Stefan Monnier
  2006-09-13 13:31   ` David Kastrup
@ 2006-09-13 13:49   ` Kim F. Storm
  2006-09-13 19:24     ` Richard Stallman
  1 sibling, 1 reply; 7+ messages in thread
From: Kim F. Storm @ 2006-09-13 13:49 UTC (permalink / raw)
  Cc: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> I was debugging a timer problem, and noticed some very odd lambda
>> forms in the timer-list.  It turns out to be the lambda generated by
>> the jit-lock code below.
>
>> Wouldn't it work just as well with the following patch?
>
> I see no reason why it shouldn't work as well.
> I just find it less elegant ;-)

I disagree, but YMMV.

Also, it's definitely not elegant when you look at the value of
timer-list :-)

Compare:

  ([nil 17671 61974 726488 nil (lambda (&rest --cl-rest--) (apply #[(G40900 G40901 G40902) "r\bJq\210\306 \x19\307\216\310\211\211\211\311\211\211\x1a^[\x1c\x1d\x1e\f\x1e\r\x1e\x0e\312\x0e\x0fJ\x0e\x10J\313\310$.
\207" [G40900 modified buffer-file-truename buffer-file-name deactivate-mark inhibit-modification-hooks buffer-modified-p ((byte-code "\b\204\b\0\301\302!\210\302\207" [modified restore-buffer-modified-p nil] 2)) t nil put-text-property fontified inhibit-point-motion-hooks inhibit-read-only buffer-undo-list G40902 G40901] 7] (quote --buf--) (quote --orig-start--) (quote --start--) --cl-rest--)) nil nil] [t 17671 61975 225097 0.5 blink-cursor-timer-function nil nil] [nil 17671 62024 0 60 display-time-event-handler nil nil])

to:

  ([nil 17671 61974 726488 nil jit-lock-fontify-again nil nil] [t 17671 61975 225097 0.5 blink-cursor-timer-function nil nil] [nil 17671 62024 0 60 display-time-event-handler nil nil])

>
>
>> *** jit-lock.el	25 Aug 2006 08:57:52 +0200	1.55
>> --- jit-lock.el	13 Sep 2006 14:12:18 +0200	
>> ***************
>> *** 397,415 ****
>>              ;; eagerly extend the refontified region with
>>              ;; jit-lock-after-change-extend-region-functions.
>>              (when (< start orig-start)
>> !              (lexical-let ((start start)
>> !                            (orig-start orig-start)
>> !                            (buf (current-buffer)))
>> !                (run-with-timer
>> !                 0 nil (lambda ()
>> !                         (with-current-buffer buf
>> !                           (with-buffer-prepared-for-jit-lock
>> !                               (put-text-property start orig-start
>> !                                                  'fontified t)))))))
>   
>>   	   ;; Find the start of the next chunk, if any.
>>   	   (setq start (text-property-any next end 'fontified nil))))))))
>   
>>   \f
>>   ;;; Stealth fontification.
>   
>> --- 397,415 ----
>>              ;; eagerly extend the refontified region with
>>              ;; jit-lock-after-change-extend-region-functions.
>>              (when (< start orig-start)
>> ! 	     (run-with-timer 0 nil 'jit-lock-fontify-again
>> ! 			     (current-buffer) start orig-start))
>   
>>   	   ;; Find the start of the next chunk, if any.
>>   	   (setq start (text-property-any next end 'fontified nil))))))))
>   
>> + (defun jit-lock-fontify-again (buf start end)
>> +   "Fontify in buffer BUF from START to END."
>> +   (with-current-buffer buf
>> +     (with-buffer-prepared-for-jit-lock
>> +      (put-text-property start end 'fontified t))))
>> + 
>> + 
>>   \f
>>   ;;; Stealth fontification.
>   
>
>> -- 
>> Kim F. Storm <storm@cua.dk> http://www.cua.dk
>
>
>
>> _______________________________________________
>> Emacs-devel mailing list
>> Emacs-devel@gnu.org
>> http://lists.gnu.org/mailman/listinfo/emacs-devel
>
>

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: jit-lock simplification?
  2006-09-13 13:31   ` David Kastrup
@ 2006-09-13 14:43     ` Stefan Monnier
  0 siblings, 0 replies; 7+ messages in thread
From: Stefan Monnier @ 2006-09-13 14:43 UTC (permalink / raw)
  Cc: emacs-devel, Kim F. Storm

>>>>> "David" == David Kastrup <dak@gnu.org> writes:

> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>>> I was debugging a timer problem, and noticed some very odd lambda
>>> forms in the timer-list.  It turns out to be the lambda generated by
>>> the jit-lock code below.
>> 
>>> Wouldn't it work just as well with the following patch?
>> 
>> I see no reason why it shouldn't work as well.
>> I just find it less elegant ;-)

> Disagree.  If `run-with-timer' has the possibility of passing values,
> that should be preferred over `lexical-let'.

My opinion obviously differs.  More specifically, I consider this ability to
pass extra values to be nothing but a hack to work around the lack of
lexical scoping in plain elisp.  Luckily, CL does provide us with lexical
scoping, and there's even hope that some future Emacs will support lexical
scoping natively.

But really, this is all a matter of taste.  If you guys want to change my
code, go for it.


        Stefan

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: jit-lock simplification?
  2006-09-13 13:49   ` Kim F. Storm
@ 2006-09-13 19:24     ` Richard Stallman
  2006-09-14 11:08       ` Kim F. Storm
  0 siblings, 1 reply; 7+ messages in thread
From: Richard Stallman @ 2006-09-13 19:24 UTC (permalink / raw)
  Cc: monnier, emacs-devel

I think it is clearer for maintenance if the timer function
has a name.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: jit-lock simplification?
  2006-09-13 19:24     ` Richard Stallman
@ 2006-09-14 11:08       ` Kim F. Storm
  0 siblings, 0 replies; 7+ messages in thread
From: Kim F. Storm @ 2006-09-14 11:08 UTC (permalink / raw)
  Cc: monnier, emacs-devel

Richard Stallman <rms@gnu.org> writes:

> I think it is clearer for maintenance if the timer function
> has a name.

Ok. I installed my change.

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2006-09-14 11:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-09-13 12:25 jit-lock simplification? Kim F. Storm
2006-09-13 13:03 ` Stefan Monnier
2006-09-13 13:31   ` David Kastrup
2006-09-13 14:43     ` Stefan Monnier
2006-09-13 13:49   ` Kim F. Storm
2006-09-13 19:24     ` Richard Stallman
2006-09-14 11:08       ` Kim F. Storm

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.