* The function naming convention used by Emacs.
@ 2021-09-26 11:05 Hongyi Zhao
2021-09-26 11:27 ` 2QdxY4RzWzUUiLuE
` (2 more replies)
0 siblings, 3 replies; 12+ messages in thread
From: Hongyi Zhao @ 2021-09-26 11:05 UTC (permalink / raw)
To: help-gnu-emacs
As far as function names are concerned, are there some established
conventions used by Emacs? For example, I noticed that there are so
many functions in Emacs named by the suffix `-p', say,
`file-exists-p', `ht-equal-p', and so on. But I still can't figure out
the meaning of this suffix. Any tips will be appreciated.
Best, HZ
--
Assoc. Prof. Hongyi Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
No. 473, Quannan West Street, Xindu District, Xingtai, Hebei province
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: The function naming convention used by Emacs.
2021-09-26 11:05 The function naming convention used by Emacs Hongyi Zhao
@ 2021-09-26 11:27 ` 2QdxY4RzWzUUiLuE
2021-09-26 11:49 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-26 11:50 ` Hongyi Zhao
2021-09-26 11:48 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-26 17:04 ` [External] : " Drew Adams
2 siblings, 2 replies; 12+ messages in thread
From: 2QdxY4RzWzUUiLuE @ 2021-09-26 11:27 UTC (permalink / raw)
To: help-gnu-emacs
On 2021-09-26 at 19:05:36 +0800,
Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
> As far as function names are concerned, are there some established
> conventions used by Emacs? For example, I noticed that there are so
> many functions in Emacs named by the suffix `-p', say,
> `file-exists-p', `ht-equal-p', and so on. But I still can't figure out
> the meaning of this suffix. Any tips will be appreciated.
The -p suffix is short for "predicate"; so file-exists-p is true if and
only if the argument names and existing file. I learned of that
convention from Common Lisp; I don't know the entire history.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: The function naming convention used by Emacs.
2021-09-26 11:05 The function naming convention used by Emacs Hongyi Zhao
2021-09-26 11:27 ` 2QdxY4RzWzUUiLuE
@ 2021-09-26 11:48 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-26 12:18 ` Hongyi Zhao
2021-09-26 17:04 ` [External] : " Drew Adams
2 siblings, 1 reply; 12+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-09-26 11:48 UTC (permalink / raw)
To: help-gnu-emacs
Hongyi Zhao wrote:
> As far as function names are concerned, are there some
> established conventions used by Emacs? For example,
> I noticed that there are so many functions in Emacs named by
> the suffix `-p', say, `file-exists-p', `ht-equal-p', and so
> on. But I still can't figure out the meaning of this suffix.
> Any tips will be appreciated.
It stands for "predicate", such a function returns t or nil.
there is also the "f" suffix for "function", e.g. `cl-incf'
and `cl-decf' ... and a couple of other conventions I can't
remember right now.
Speaking of CL, the convention for *global-variables* is not
encouraged in Elisp.
Other than that do this
(require 'checkdoc)
(setq checkdoc-permit-comma-termination-flag t)
(defun check-package-style ()
(interactive)
(let ((msg "Style check..."))
(message msg)
(checkdoc-current-buffer t) ; TAKE-NOTES
(message "%sdone" msg) ))
(defalias 'check-style #'check-package-style)
and do byte-compile for more pointers ...
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: The function naming convention used by Emacs.
2021-09-26 11:27 ` 2QdxY4RzWzUUiLuE
@ 2021-09-26 11:49 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-26 11:50 ` Hongyi Zhao
1 sibling, 0 replies; 12+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-09-26 11:49 UTC (permalink / raw)
To: help-gnu-emacs
2QdxY4RzWzUUiLuE wrote:
>> As far as function names are concerned, are there some
>> established conventions used by Emacs? For example,
>> I noticed that there are so many functions in Emacs named
>> by the suffix `-p', say, `file-exists-p', `ht-equal-p', and
>> so on. But I still can't figure out the meaning of this
>> suffix. Any tips will be appreciated.
>
> The -p suffix is short for "predicate"; so file-exists-p is
> true if and only if the argument names and existing file.
> I learned of that convention from Common Lisp; I don't know
> the entire history.
Me neither :)
But it is from Predicate Logic which is an extension of
Propositional Logic ...
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: The function naming convention used by Emacs.
2021-09-26 11:27 ` 2QdxY4RzWzUUiLuE
2021-09-26 11:49 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-09-26 11:50 ` Hongyi Zhao
1 sibling, 0 replies; 12+ messages in thread
From: Hongyi Zhao @ 2021-09-26 11:50 UTC (permalink / raw)
To: help-gnu-emacs
On Sun, Sep 26, 2021 at 7:27 PM <2QdxY4RzWzUUiLuE@potatochowder.com> wrote:
[...]
> The -p suffix is short for "predicate"; so file-exists-p is true if and
> only if the argument names and existing file. I learned of that
> convention from Common Lisp; I don't know the entire history.
Thank you for sharing your knowledge with me.
HZ
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: The function naming convention used by Emacs.
2021-09-26 11:48 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-09-26 12:18 ` Hongyi Zhao
2021-09-26 13:34 ` Emanuel Berg via Users list for the GNU Emacs text editor
0 siblings, 1 reply; 12+ messages in thread
From: Hongyi Zhao @ 2021-09-26 12:18 UTC (permalink / raw)
To: Emanuel Berg, help-gnu-emacs
On Sun, Sep 26, 2021 at 7:49 PM Emanuel Berg via Users list for the
GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:
>
> Hongyi Zhao wrote:
>
> > As far as function names are concerned, are there some
> > established conventions used by Emacs? For example,
> > I noticed that there are so many functions in Emacs named by
> > the suffix `-p', say, `file-exists-p', `ht-equal-p', and so
> > on. But I still can't figure out the meaning of this suffix.
> > Any tips will be appreciated.
>
> It stands for "predicate", such a function returns t or nil.
>
> there is also the "f" suffix for "function", e.g. `cl-incf'
> and `cl-decf' ... and a couple of other conventions I can't
> remember right now.
>
> Speaking of CL, the convention for *global-variables* is not
> encouraged in Elisp.
>
> Other than that do this
>
> (require 'checkdoc)
>
> (setq checkdoc-permit-comma-termination-flag t)
>
> (defun check-package-style ()
> (interactive)
> (let ((msg "Style check..."))
> (message msg)
> (checkdoc-current-buffer t) ; TAKE-NOTES
> (message "%sdone" msg) ))
> (defalias 'check-style #'check-package-style)
Do you mean and suggest adding the above code snippets into the init file?
> and do byte-compile for more pointers ...
I now use the `--with-native-compilation' option to configure Emacs
for compilation. So, the thing you mentioned above should have been
done automatically by Emacs.
HZ
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: The function naming convention used by Emacs.
@ 2021-09-26 13:32 Pierpaolo Bernardi
2021-09-26 13:35 ` Emanuel Berg via Users list for the GNU Emacs text editor
0 siblings, 1 reply; 12+ messages in thread
From: Pierpaolo Bernardi @ 2021-09-26 13:32 UTC (permalink / raw)
To: Emanuel Berg, help-gnu-emacs@gnu org
Il giorno 26 settembre 2021, alle ore 13:49, Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> ha scritto:
>there is also the "f" suffix for "function", e.g. `cl-incf'
>and `cl-decf' ...
The "f" in these cases stands for "field".
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: The function naming convention used by Emacs.
2021-09-26 12:18 ` Hongyi Zhao
@ 2021-09-26 13:34 ` Emanuel Berg via Users list for the GNU Emacs text editor
0 siblings, 0 replies; 12+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-09-26 13:34 UTC (permalink / raw)
To: help-gnu-emacs
Hongyi Zhao wrote:
>> Other than that do this
>>
>> (require 'checkdoc)
>>
>> (setq checkdoc-permit-comma-termination-flag t)
>>
>> (defun check-package-style ()
>> (interactive)
>> (let ((msg "Style check..."))
>> (message msg)
>> (checkdoc-current-buffer t) ; TAKE-NOTES
>> (message "%sdone" msg) ))
>> (defalias 'check-style #'check-package-style)
>
> Do you mean and suggest adding the above code snippets into
> the init file?
Yes, if you will. And use it on your code.
>> and do byte-compile for more pointers ...
>
> I now use the `--with-native-compilation' option to
> configure Emacs for compilation. So, the thing you mentioned
> above should have been done automatically by Emacs.
Byte-compile your code after you've written it. Do it again
when you change it. Byte-compiling makes it faster to load and
run, that's the reason to do it. But as a positive
side-effect, the byte-compiler will also output errors and
warnings - so it is a tool to improve you code as well.
Do a Makefile and shell alias to it to run it, so you can
byte-compile fast in terms of the mere interface, but also so
that files you didn't change and have already byte-compiled
will not be byte-compiled again.
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: The function naming convention used by Emacs.
2021-09-26 13:32 Pierpaolo Bernardi
@ 2021-09-26 13:35 ` Emanuel Berg via Users list for the GNU Emacs text editor
0 siblings, 0 replies; 12+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-09-26 13:35 UTC (permalink / raw)
To: help-gnu-emacs
Pierpaolo Bernardi wrote:
>> there is also the "f" suffix for "function", e.g. `cl-incf'
>> and `cl-decf' ...
>
> The "f" in these cases stands for "field".
That so, OK, thanks.
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 12+ messages in thread
* RE: [External] : The function naming convention used by Emacs.
2021-09-26 11:05 The function naming convention used by Emacs Hongyi Zhao
2021-09-26 11:27 ` 2QdxY4RzWzUUiLuE
2021-09-26 11:48 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-09-26 17:04 ` Drew Adams
2021-09-27 5:46 ` Hongyi Zhao
2 siblings, 1 reply; 12+ messages in thread
From: Drew Adams @ 2021-09-26 17:04 UTC (permalink / raw)
To: Hongyi Zhao, help-gnu-emacs
> As far as function names are concerned, are there some established
> conventions used by Emacs? For example, I noticed that there are so
> many functions in Emacs named by the suffix `-p', say,
> `file-exists-p', `ht-equal-p', and so on. But I still can't figure
> out the meaning of this suffix. Any tips will be appreciated.
Ask Emacs!
In the Elisp manual, `i' followed by `convention'
(if you have substring completion turned on) shows
these index-entry candidates (the exact list might
depend on your Emacs version):
buffer display conventions
coding conventions in Emacs Lisp
comments, Lisp convention for
conventions for writing major modes
conventions for writing minor modes
documentation conventions
documentation strings, conventions and tips
key binding, conventions for
major mode conventions
minor mode conventions
programming conventions
set-advertised-calling-convention
typographic conventions
Some of those point to the same nodes of the manual.
Choosing, say, `coding conventions in Emacs Lisp'
takes you to node `Coding Conventions', where you
find this:
• If the purpose of a function is to tell you
whether a certain condition is true or false,
give the function a name that ends in ‘p’
(which stands for “predicate”). If the name
is one word, add just ‘p’; if the name is
multiple words, add ‘-p’. Examples are
‘framep’ and ‘frame-live-p’.
https://www.gnu.org/software/emacs/manual/html_node/elisp/Coding-Conventions.html
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [External] : The function naming convention used by Emacs.
2021-09-26 17:04 ` [External] : " Drew Adams
@ 2021-09-27 5:46 ` Hongyi Zhao
2021-09-27 14:53 ` Drew Adams
0 siblings, 1 reply; 12+ messages in thread
From: Hongyi Zhao @ 2021-09-27 5:46 UTC (permalink / raw)
To: Drew Adams; +Cc: help-gnu-emacs
On Mon, Sep 27, 2021 at 1:04 AM Drew Adams <drew.adams@oracle.com> wrote:
>
> > As far as function names are concerned, are there some established
> > conventions used by Emacs? For example, I noticed that there are so
> > many functions in Emacs named by the suffix `-p', say,
> > `file-exists-p', `ht-equal-p', and so on. But I still can't figure
> > out the meaning of this suffix. Any tips will be appreciated.
>
> Ask Emacs!
>
> In the Elisp manual, `i' followed by `convention'
> (if you have substring completion turned on)
What's the exact vanilla Emacs keystrokes corresponding to the above operations?
> shows these index-entry candidates (the exact list might
> depend on your Emacs version):
>
> buffer display conventions
> coding conventions in Emacs Lisp
> comments, Lisp convention for
> conventions for writing major modes
> conventions for writing minor modes
> documentation conventions
> documentation strings, conventions and tips
> key binding, conventions for
> major mode conventions
> minor mode conventions
> programming conventions
> set-advertised-calling-convention
> typographic conventions
>
> Some of those point to the same nodes of the manual.
>
> Choosing, say, `coding conventions in Emacs Lisp'
> takes you to node `Coding Conventions', where you
> find this:
>
> • If the purpose of a function is to tell you
> whether a certain condition is true or false,
> give the function a name that ends in ‘p’
> (which stands for “predicate”). If the name
> is one word, add just ‘p’; if the name is
> multiple words, add ‘-p’. Examples are
> ‘framep’ and ‘frame-live-p’.
>
> https://www.gnu.org/software/emacs/manual/html_node/elisp/Coding-Conventions.html
Thank you for showing me this. With swiper [1], I use the following
command to access the above Elisp manual built-in Emacs:
C-h i RET elisp RET cod conv RET
[1] https://github.com/abo-abo/swiper
HZ
^ permalink raw reply [flat|nested] 12+ messages in thread
* RE: [External] : The function naming convention used by Emacs.
2021-09-27 5:46 ` Hongyi Zhao
@ 2021-09-27 14:53 ` Drew Adams
0 siblings, 0 replies; 12+ messages in thread
From: Drew Adams @ 2021-09-27 14:53 UTC (permalink / raw)
To: Hongyi Zhao; +Cc: help-gnu-emacs
> > In the Elisp manual, `i' followed by `convention'
> > (if you have substring completion turned on)
>
> What's the exact vanilla Emacs keystrokes
> corresponding to the above operations?
With vanilla Emacs, enable style `substring' for
user option `completion-styles', if you want to
be able to type just `convention' and see
substring matches (completions) for it.
In the Elisp manual, `i completion-styles RET'
tells you about this.
Then `i convention TAB' does what I described.
If you don't enable substring completion then
`i convention TAB' completes only to `conventions
for writing m', and `TAB' again shows you these
two candidates:
conventions for writing major modes
conventions for writing minor modes
Neither of those is relevant for your question.
But you can instead type `i coding c TAB' to
get candidate `coding conventions in Emacs Lisp'.
The problem with that is guessing/knowing more
about what index entries there might be.
This illustrates a general point: vanilla Emacs
completion is limited, out of the box. But you
can customize it to help you better. You'll
need to read about `completion-styles' to decide
just how you want to do that.
Personally, I use a completion library (Icicles)
that provides both (1) "prefix" completion
(speaking generally) such as what vanilla Emacs
provides - using `TAB', and (2) "apropos"
completion such as regexp (which includes
substring) matching - using `S-TAB'. So I use
`i convention S-TAB' to see substring matches.
https://www.emacswiki.org/emacs/Icicles_-_Completion_Methods_and_Styles
[
I use those names, "prefix" and "apropos", but
they're a bit misleading. In Icicles, "prefix"
completion (`TAB') includes whatever vanilla
Emacs `completion-styles' you configured (so it
can include `substring', `flex', etc.). And it
includes `fuzzy' and `swank' completion.
"Apropos" completion includes 2 kinds of "scatter"
completion (sometimes called "flex"), and 3 other
kinds of "fuzzy" completion. (And you can add
other matching methods.)
Having two keys for completion means you can
use either kind anytime, and you can use them
together when progressively narrowing. Each
has its own advantages.
(You can also change the method used for either
`TAB' or `S-TAB' anytime, during completion.)
]
> With swiper, I use the following command to
> access the above Elisp manual built-in Emacs:
>
> C-h i RET elisp RET cod conv RET
Same with Icicles, and no doubt with other
libraries.
It's enough to type just `cod co'. But again,
this means you have to guess that there's an
index entry that's something like `coding
conventions'. Otherwise, how would you come up
with `cod co'?
It's not about how little you can type to match
just what you need. It's about what you need
to guess, to get to what you need.
Guessing that there's some info (an answer)
about "conventions" is fairly natural, here.
Guessing there might be info for "coding" might
also be natural (or not). With uncustomized
vanilla Emacs, if you try just `coding TAB'
you'll get about 20 candidates. If you try just
`convention' you'll get the two candidates I
cited above (neither of which is relevant here).
You might guess "programming" instead of "coding".
And there is an index entry `programming
conventions'. But that takes you to node
`Programming Tips', which doesn't help with your
quest.
1. My point was to _ask Emacs_, using its index.
(And you can of course also just go directly to
node `Index' and browse/search there, instead of
using `i'.)
2. A secondary point is that you can help yourself
by using a better matching style or system than
the default.
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2021-09-27 14:53 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-26 11:05 The function naming convention used by Emacs Hongyi Zhao
2021-09-26 11:27 ` 2QdxY4RzWzUUiLuE
2021-09-26 11:49 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-26 11:50 ` Hongyi Zhao
2021-09-26 11:48 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-26 12:18 ` Hongyi Zhao
2021-09-26 13:34 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-26 17:04 ` [External] : " Drew Adams
2021-09-27 5:46 ` Hongyi Zhao
2021-09-27 14:53 ` Drew Adams
-- strict thread matches above, loose matches on Subject: below --
2021-09-26 13:32 Pierpaolo Bernardi
2021-09-26 13:35 ` Emanuel Berg via Users list for the GNU Emacs text editor
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).