Re: Improving add-hook of two functions

tpeplt <[email protected]> Tue, 07 Jul 2026 10:15:52 -0400
Newsgroups gmane.emacs.help
Message-ID <[email protected]>
uzibalqa <[email protected]> writes:

>> 
>> Using ‘cl-case’ can simplify this binding expression to:
>> 
>>    (hka (cl-case actm
>>           ((add add-regexp add-outline)          #'add-hook)
>>           ((remove remove-regexp remove-outline) #'remove-hook)
>>           (otherwise (error "%s: ACTM %s is invalid"
>>                             "kronaire-hooks" actm))))
>> 
>
> I figured the capability of string-match-p like so
>
>   (let* ( (sbn     (symbol-name actm))
>           (add-rx  "^add\\(-regexp\\|-outline\\)?$") 
>           (rmv-rx  "^remove\\(-regexp\\|-outline\\)?$")
>           (hka     (cond
>                       ((string-match-p add-rx sbn)  'add-hook)
>                       ((string-match-p rmv-rx sbn)  'remove-hook)
>                       (t (message (format "%s: Invalid ACTM %s"
>                                 "kronaire-hooks" actm))))) )
>

If you want to continue using ‘cond’ in your solution, then
simply expanding the ‘cl-case’ macro expression, above, will
give you that in Emacs Lisp:

   (cond ((cl-member actm '(add add-regexp add-outline)) #'add-hook)
         ((cl-member actm '(remove remove-regexp remove-outline)) #'remove-hook)
         (t (error "%s: ACTM %s is invalid" "kronaire-hooks" actm)))

But this has the duplication in the code that almost
certainly was the reason that ‘case’ was written into the
language 40 to 50 (?) years ago by experienced Lisp
programmers.

-- 
The lyf so short, the craft so long to lerne.
- Geoffrey Chaucer, The Parliament of Birds.