Re: feature/android a5b74e2ff62: Initialize text conversion hooks for each C Mode buffer

Po Lu via CC-Mode-help <[email protected]> Sat, 28 Oct 2023 08:16:41 +0800
Newsgroups gmane.emacs.cc-mode.general
Message-ID <[email protected]>
Stefan Monnier <[email protected]> writes:

> Hi Po Lu (and Alan),
>
> Regarding this patch of yours from a few months back:
>
>> diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
>> index 1364117bdc8..88e0aebb9a2 100644
>> --- a/lisp/progmodes/cc-mode.el
>> +++ b/lisp/progmodes/cc-mode.el
>> @@ -251,13 +251,14 @@ control).  See \"cc-mode.el\" for more info."
>>              (when (fboundp 'electric-indent-local-mode)
>>  	      (add-hook 'electric-indent-mode-hook 'c-electric-indent-mode-hook)
>>                (add-hook 'electric-indent-local-mode-hook
>> -                        'c-electric-indent-local-mode-hook))
>> -	    ;; Set up text conversion, for Emacs >= 30.0
>> -	    (when (boundp 'post-text-conversion-hook)
>> -	      (add-hook 'post-text-conversion-hook #'c-post-text-conversion)))
>> +                        'c-electric-indent-local-mode-hook)))
>>  	;; Will try initialization hooks again if they failed.
>>  	(put 'c-initialize-cc-mode initprop c-initialization-ok))))
>>  
>> +  ;; Set up text conversion, for Emacs >= 30.0
>> +  (when (boundp 'post-text-conversion-hook)
>> +    (add-hook 'post-text-conversion-hook #'c-post-text-conversion))
>> +
>>    (unless new-style-init
>>      (c-init-language-vars-for 'c-mode)))
>
> Why is this specific to CC-mode?
> Is it because other modes handle electricity via the
> `post-self-insert-hook` instead?

Correct.

> And why is the hook function added globally?
> Wouldn't it be better to add it buffer-locally instead?

It's installed buffer-locally, since the hook variable itself is
buffer-local.

Thanks.