GNU bug report logs -
#79178
[Improvement] Allow auto-insert to have functions as conditions
Previous Next
To reply to this bug, email your comments to 79178 AT debbugs.gnu.org.
There is no need to reopen the bug first.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#79178
; Package
emacs
.
(Tue, 05 Aug 2025 16:18:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Mattias <mattias <at> kojin.tech>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Tue, 05 Aug 2025 16:18:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
--text follows this line--
Hi everyone,
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
[0001-Autoinsert-Allow-condition-to-be-a-function.patch (text/x-patch, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#79178
; Package
emacs
.
(Wed, 06 Aug 2025 11:34:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 79178 <at> debbugs.gnu.org (full text, mbox):
> 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.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#79178
; Package
emacs
.
(Wed, 06 Aug 2025 14:47:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 79178 <at> debbugs.gnu.org (full text, mbox):
[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)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#79178
; Package
emacs
.
(Thu, 07 Aug 2025 13:06:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 79178 <at> debbugs.gnu.org (full text, mbox):
> Date: Wed, 6 Aug 2025 16:46:25 +0200
> Cc: 79178 <at> debbugs.gnu.org
> From: Mattias <mattias <at> kojin.tech>
>
> Thanks for the review!
>
> I think I did everything you asked, let me know if there's something
> missing or not done properly ;-)
Thanks, a couple of minor comments below.
> * lisp/autoinsert.el:
> (auto-insert-alist): Add the new condition type to the variable
> documentation
> (auto-insert): Change the way the condition is matched to allow for
> custom predicates
This should be formatted as below:
* lisp/autoinsert.el: (auto-insert-alist): Add the new condition
type to the variable documentation.
(auto-insert): Change the way the condition is matched to allow for
custom predicates.
It is best to use change-log-mode for formatting commit log messages,
as it will allow you to use M-q and other conveniences, and will obey
the formatting according to our conventions. Also, don't forget the
periods at the end of each sentence (I added them above).
> +** Autoinsert
> +
> +*** New condition for 'auto-insert-alist'.
> +'auto-insert-alist' now also allows to have a predicate taking no argument
> +as conditions. This allows to trigger 'auto-insert' with finer grained control.
Our convention is to leave 2 spaces between sentences. Also, since
the manual was updated, the NEWS entry should be marked with "+++"
(see the explanation at the beginning of NEWS).
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#79178
; Package
emacs
.
(Thu, 07 Aug 2025 13:19:01 GMT)
Full text and
rfc822 format available.
Message #17 received at 79178 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Hi and thanks again,
> It is best to use change-log-mode for formatting commit log messages,
> as it will allow you to use M-q and other conveniences, and will obey
> the formatting according to our conventions. Also, don't forget the
> periods at the end of each sentence (I added them above).
I tried using change-log-mode but it indented the whole commit
message with 4 spaces when I used M-q on it. My current mode seems to do
the job with M-q, I just didn't use it before (and it removes the :
between lisp/autoinsert and (auto-insert-alist) which looks like the
intended formatting since other commit logs are formatted this way).
[0001-bug-79178-Autoinsert-Allow-condition-to-be-a-functio.patch (text/x-patch, attachment)]
Reply sent
to
Eli Zaretskii <eliz <at> gnu.org>
:
You have taken responsibility.
(Thu, 07 Aug 2025 14:42:02 GMT)
Full text and
rfc822 format available.
Notification sent
to
Mattias <mattias <at> kojin.tech>
:
bug acknowledged by developer.
(Thu, 07 Aug 2025 14:42:02 GMT)
Full text and
rfc822 format available.
Message #22 received at 79178-done <at> debbugs.gnu.org (full text, mbox):
> Date: Thu, 7 Aug 2025 15:18:43 +0200
> Cc: 79178 <at> debbugs.gnu.org
> From: Mattias <mattias <at> kojin.tech>
>
> Hi and thanks again,
>
> > It is best to use change-log-mode for formatting commit log messages,
> > as it will allow you to use M-q and other conveniences, and will obey
> > the formatting according to our conventions. Also, don't forget the
> > periods at the end of each sentence (I added them above).
>
> I tried using change-log-mode but it indented the whole commit
> message with 4 spaces when I used M-q on it. My current mode seems to do
> the job with M-q, I just didn't use it before (and it removes the :
> between lisp/autoinsert and (auto-insert-alist) which looks like the
> intended formatting since other commit logs are formatted this way).
Thanks, installed on the master branch (with a few tiny fixes), and
closing the bug.
This bug report was last modified 8 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.