unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* include clause in interactive command
@ 2024-11-30 11:38 Heime via Users list for the GNU Emacs text editor
  2024-12-01  4:42 ` Zhengyi Fu
  0 siblings, 1 reply; 5+ messages in thread
From: Heime via Users list for the GNU Emacs text editor @ 2024-11-30 11:38 UTC (permalink / raw)
  To: Heime via Users list for the GNU Emacs text editor


I have an interactive function that changes some buffer settings.  
But it also has an include clause (include 'orellana). 

Would one usually recommend calling it only once, or calling it 
everytime a user uses the function is ok?



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: include clause in interactive command
  2024-11-30 11:38 include clause in interactive command Heime via Users list for the GNU Emacs text editor
@ 2024-12-01  4:42 ` Zhengyi Fu
  2024-12-01 12:00   ` Heime via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 5+ messages in thread
From: Zhengyi Fu @ 2024-12-01  4:42 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

On 2024-11-30 19:38, Heime via Users list for the GNU Emacs text editor 
wrote:
> I have an interactive function that changes some buffer settings.
> But it also has an include clause (include 'orellana).
> 
> Would one usually recommend calling it only once, or calling it
> everytime a user uses the function is ok?

What is an “include clause”?



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: include clause in interactive command
  2024-12-01  4:42 ` Zhengyi Fu
@ 2024-12-01 12:00   ` Heime via Users list for the GNU Emacs text editor
  2024-12-02  7:07     ` Tassilo Horn
  2024-12-02  7:50     ` mbork
  0 siblings, 2 replies; 5+ messages in thread
From: Heime via Users list for the GNU Emacs text editor @ 2024-12-01 12:00 UTC (permalink / raw)
  To: Zhengyi Fu; +Cc: Heime via Users list for the GNU Emacs text editor






Sent with Proton Mail secure email.

On Sunday, December 1st, 2024 at 4:42 PM, Zhengyi Fu <i@fuzy.me> wrote:

> On 2024-11-30 19:38, Heime via Users list for the GNU Emacs text editor
> wrote:
> 
> > I have an interactive function that changes some buffer settings.
> > But it also has an include clause (include 'orellana).
> > 
> > Would one usually recommend calling it only once, or calling it
> > everytime a user uses the function is ok?
> 
> 
> What is an “include clause”?

A mistake.  I am referring to require.

For instance, this will call require everytime the function is called
interactively.  Should one call the require only once and avoid an 
interactive function from calling a require command each time?  

(defun feruler ()
  (interactive)

  (require 'ruler-mode)
  (set-face-attribute 'ruler-mode-current-column nil
    :background "#ff4500" :foreground "#ffffff"))






^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: include clause in interactive command
  2024-12-01 12:00   ` Heime via Users list for the GNU Emacs text editor
@ 2024-12-02  7:07     ` Tassilo Horn
  2024-12-02  7:50     ` mbork
  1 sibling, 0 replies; 5+ messages in thread
From: Tassilo Horn @ 2024-12-02  7:07 UTC (permalink / raw)
  To: Heime via Users list for the GNU Emacs text editor; +Cc: Zhengyi Fu, Heime

Heime via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> writes:

> A mistake.  I am referring to require.
>
> For instance, this will call require everytime the function is called
> interactively.  Should one call the require only once and avoid an
> interactive function from calling a require command each time?
>
> (defun feruler ()
>   (interactive)
>
>   (require 'ruler-mode)
>   (set-face-attribute 'ruler-mode-current-column nil
>     :background "#ff4500" :foreground "#ffffff"))

That's no problem, nothing will happen if it's already loaded (as
indicated by the `require' docs).  It can be suitable in cases where
your program/mode usually doesn't use ruler-mode but only this or some
interactive commands like feruler use it.  In that case, ruler-mode is
only loaded when it's actually used/needed.

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: include clause in interactive command
  2024-12-01 12:00   ` Heime via Users list for the GNU Emacs text editor
  2024-12-02  7:07     ` Tassilo Horn
@ 2024-12-02  7:50     ` mbork
  1 sibling, 0 replies; 5+ messages in thread
From: mbork @ 2024-12-02  7:50 UTC (permalink / raw)
  To: Heime via Users list for the GNU Emacs text editor; +Cc: Zhengyi Fu, Heime

On 2024-12-01, at 12:00, Heime via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:

> Sent with Proton Mail secure email.
>
> On Sunday, December 1st, 2024 at 4:42 PM, Zhengyi Fu <i@fuzy.me> wrote:
>
>> On 2024-11-30 19:38, Heime via Users list for the GNU Emacs text editor
>> wrote:
>> 
>> > I have an interactive function that changes some buffer settings.
>> > But it also has an include clause (include 'orellana).
>> > 
>> > Would one usually recommend calling it only once, or calling it
>> > everytime a user uses the function is ok?
>> 
>> 
>> What is an “include clause”?
>
> A mistake.  I am referring to require.

Per the manual:

--8<---------------cut here---------------start------------->8---
This function checks whether FEATURE is present in the current
Emacs session (using ‘(featurep FEATURE)’; see below).  The
argument FEATURE must be a symbol.
--8<---------------cut here---------------end--------------->8---

(https://www.gnu.org/software/emacs/manual/html_node/elisp/Named-Features.html)

So, there should be very little penalty to calling `require' in your
command (especially that it is coded in C, not Elisp).

OTOH, it might be not necessary.  If what you need from the required
library has the `autoload' cookie
(https://www.gnu.org/software/emacs/manual/html_node/elisp/Autoload.html),
the library will be loaded automatically the first time you use the
autoloaded function.

Hth,

-- 
Marcin Borkowski
https://mbork.pl
https://crimsonelevendelightpetrichor.net/



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-12-02  7:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-30 11:38 include clause in interactive command Heime via Users list for the GNU Emacs text editor
2024-12-01  4:42 ` Zhengyi Fu
2024-12-01 12:00   ` Heime via Users list for the GNU Emacs text editor
2024-12-02  7:07     ` Tassilo Horn
2024-12-02  7:50     ` mbork

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).