I recently noticed an issue in man.el, in which sections in Man--sections are listed backwards. That is, the value is is something like:
(#("SEE ALSO" 0 8
(face Man-overstrike))
#("COPYRIGHT" 0 9
(face Man-overstrike))
#("REPORTING BUGS" 0 14
(face Man-overstrike))
#("AUTHOR" 0 6
(face Man-overstrike))
#("EXAMPLES" 0 8
(face Man-overstrike))
#("DESCRIPTION" 0 11
(face Man-overstrike))
#("SYNOPSIS" 0 8
(face Man-overstrike))
#("NAME" 0 4
(face Man-overstrike)))
This is because Man-build-section-alist scans the buffer from (point-min) to (point-max), push-ing values onto Man--sections as it goes.
I wanted to change this behavior so that the sections are in the correct order, which matters to helm-mode.
However, changing the Man-build-section-alist function, then re-evaluating it doesn't do any good, because it's defined with defsubst instead of defun. defsubst inlines functions, which means that, when the file is byte-compiled, the function definition is directly inserted where the function is called. This means that redefining/evaluating the function doesn't work, since the bytecode is not changed.
defsubst offers a performance benefit, but is there really any reason to use it for a command like Man-build-section-alist? Most functions in man.el use defun, and I can't imagine that the performance benefit matters on hardware from the past 15 years.
defsubstnowadays. People sometimes think that a function (often a tiny one, but that makes no difference) will never need to be used by anyone (a user, using Lisp). They are almost always wrong in principle, and almost almost always wrong in practice. I think it comes from a shortsighted view of Lisp users, and perhaps from an ingrained notion of a separation between "developers" and "users" - a notion that some bring to Emacs from other kinds of programming, in other contexts (e.g., not for user interaction). -- Just one opinion. – Drew Sep 16 '16 at 04:16defmacro, notdefsubst. If you need a function because it will befuncalled orapplyed or mapped, usedefun, notdefsubst. Show me a case wheredefsubstis used and I'm pretty sure it should not be used. – Drew Sep 16 '16 at 04:20defmacroshould be used just for a performance boost. Macros are used to extend the language, and carry costs (e.g. more difficult to reason about and debug). – Tianxiang Xiong Sep 16 '16 at 05:39defsubst. – Drew Sep 16 '16 at 15:00defmacro, notdefsubst" - that makes no sense,defmacrohas all the drawbacks ofdefsubstand additionally the code will be more complicated by the multiple phases of evaluation (I agree thatdefsubstis usually a bad idea, typically premature optimization) – npostavs Sep 16 '16 at 15:47defsubst- that, combined with the ability to be invoked as a function (whichdefmacrolacks). And for that reason (alone),defmacrois better thandefsubst. (I cannot edit my older comment to clarify it.) – Drew Sep 16 '16 at 16:01define-inlinemacro which can be used in those cases where performance is important.define-inlineis a kind of halfway betweendefsubstanddefmacro: it defines a function (i.e.funcallable) but you can optimize it when it's inlined. It's not as simple to use asdefsubst, but results in more efficient code. – Stefan Sep 17 '16 at 19:54define-inlineseems like a chore to use, withinline-quote,inline-letevals, and a whole bunch of other macros to go along with it. – Tianxiang Xiong Sep 17 '16 at 20:08M-x report-emacs-bugsaying that it's OK for a defsubst function to be inlined, but it should be de/re-inlined whenever its definition changes (i.e. Emacs should keep track of those inlinings and keep them uptodate). – Stefan Sep 17 '16 at 20:16