GNU bug report logs - #79178
[Improvement] Allow auto-insert to have functions as conditions

Previous Next

Package: emacs;

Reported by: Mattias <mattias <at> kojin.tech>

Date: Tue, 5 Aug 2025 16:18:02 UTC

Severity: normal

Done: Eli Zaretskii <eliz <at> gnu.org>

Full log


View this message in rfc822 format

From: Mattias <mattias <at> kojin.tech>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 79178 <at> debbugs.gnu.org
Subject: bug#79178: [Improvement] Allow auto-insert to have functions as conditions
Date: Wed, 6 Aug 2025 16:46:25 +0200
[Message part 1 (text/plain, inline)]
Hi Eli,

Thanks for the review!

I think I did everything you asked, let me know if there's something 
missing or not done properly ;-)

Mattias

Le 06/08/2025 à 13:33, Eli Zaretskii a écrit :
>> Date: Tue, 5 Aug 2025 18:16:48 +0200
>> From: Mattias <mattias <at> kojin.tech>
>>
>> First contribution to emacs. This comes from the fact that I have a
>> custom function that overrides auto-insert to fit my needs and I
>> realised it was not a big change and could be merged into emacs directly.
>>
>> This small patch aims to allow any function acting as a predicate with
>> no arguments to be used as a condition in auto-insert-alist
> Thanks.  Changes like this one should be called out in NEWS.  In
> addition, auto-insert is described in a manual (see
> doc/misc/autotype.texi), which should be updated due to this change.
>
>> Currently a condition can only be a regexp or a major-mode symbol but
>> there's no real reason to not allow any predicate as a condition
> This log message is incomplete: it lacks the record of the file and
> the functions/variables which are modified by the patch.  See "git
> log" for examples of how we format commit log messages.
>
>> +CONDITION may be a regexp that must match the new file's name, a symbol that
>> +must match the major mode for this element to apply or a custom predicate that
>> +takes no argument.
> This addition makes the sentence too long and hard to read and grasp.
> Suggest to break it in two:
>
>    CONDITION may be a regexp that must match the new file's name, or
>    a symbol that must match the major mode for this element to apply.
>    CONDITION could also be a predicate function of no arguments; Emacs
>    will insert the text if the predicate function returns non-nil,
>
>> +                    ;; if `cond' is a lambda, don't split it but set `desc' to a custom string
>> +                    (if (and (not (symbolp cond)) (functionp cond))
>> +                        (setq desc "`lambda condition'")
>> +                      (setq desc (cdr cond)
>> +                            cond (car cond))))
>> +                  (when (cond
>> +                         ;; cond should be a major-mode variable
>> +                         ((and (symbolp cond) (not (functionp cond)))
>> +                          (derived-mode-p cond))
>> +
>> +                         ;; cond should be a predicate that takes no argument
>> +                         ;; It can either be a named function or a lambda
>> +                         ((functionp cond)
>> +                          (funcall cond))
>> +
>> +                         ;; cond should be a regexp
> Please be consistent, and quote 'cond' in all of these comments.
>
> P.S. Since the number of the bug is now known, please mention the bug
> number in the commit log message when you submit the updated patch.
[0001-bug-79178-Autoinsert-Allow-condition-to-be-a-functio.patch (text/x-patch, attachment)]

This bug report was last modified 9 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.