unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* fill-column setq-default and add-hook
@ 2024-11-30 17:38 Heime via Users list for the GNU Emacs text editor
  2024-12-04 12:00 ` Joel Reicher
  0 siblings, 1 reply; 4+ messages in thread
From: Heime via Users list for the GNU Emacs text editor @ 2024-11-30 17:38 UTC (permalink / raw)
  To: Heime via Users list for the GNU Emacs text editor



I want to understand the setting of fill-column.  It is a buffer local variable.  

But then there the following possibilities 

   (setq-default fill-column 72)

and       

   (add-hook 'prog-mode-hook  (lambda () (setq fill-column 72)))

The first sets fill-column globally.  What does that mean?  I interpret
that the value is set globally but only to those buffers for which there
is no local binding.  This setting the value (setq-default fill-column 72)
does not always work for the current buffer.  How can one solve this problem?

What does the mode hook do exactly?
  





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

* Re: fill-column setq-default and add-hook
  2024-11-30 17:38 fill-column setq-default and add-hook Heime via Users list for the GNU Emacs text editor
@ 2024-12-04 12:00 ` Joel Reicher
  2024-12-04 12:39   ` Heime via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 4+ messages in thread
From: Joel Reicher @ 2024-12-04 12:00 UTC (permalink / raw)
  To: Heime via Users list for the GNU Emacs text editor; +Cc: Heime

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

> I want to understand the setting of fill-column.  It is a buffer 
> local variable.
>
> But then there the following possibilities
>
>    (setq-default fill-column 72)
>
> and
>
>    (add-hook 'prog-mode-hook  (lambda () (setq fill-column 72)))
>
> The first sets fill-column globally.

It sets a default value, which is a different instance than any of 
the buffer local instances. ("Instance" is not strictly the 
correct term, but I'm trying it on.)

> What does that mean?  I interpret that the value is set globally 
> but only to those buffers for which there is no local binding.

It doesn't set anything for a buffer. It sets the default 
instance. Any buffer that lacks a local instance will use that 
default instance. Any local instance created after that will 
default to the value of that default instance.

> This setting the value (setq-default fill-column 72) does not 
> always work for the current buffer.

It's not really doing anything to any buffer. It's doing something 
to the default instance. The question of which buffers (if any) 
use that instance is separate.

> How can one solve this problem?

If you want to set the current buffer's value, use setq.

> What does the mode hook do exactly?

When you enter a mode derived from prog-mode, it will set 
fill-column to 72, which for that variable creates a buffer local 
instance of it (and sets that instance).

Regards,

        - Joel



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

* Re: fill-column setq-default and add-hook
  2024-12-04 12:00 ` Joel Reicher
@ 2024-12-04 12:39   ` Heime via Users list for the GNU Emacs text editor
  2024-12-05  1:46     ` Joel Reicher
  0 siblings, 1 reply; 4+ messages in thread
From: Heime via Users list for the GNU Emacs text editor @ 2024-12-04 12:39 UTC (permalink / raw)
  To: Joel Reicher; +Cc: Heime via Users list for the GNU Emacs text editor






Sent with Proton Mail secure email.

On Thursday, December 5th, 2024 at 12:00 AM, Joel Reicher <joel.reicher@gmail.com> wrote:

> Heime via Users list for the GNU Emacs text editor
> help-gnu-emacs@gnu.org writes:
> 
> > I want to understand the setting of fill-column. It is a buffer
> > local variable.
> > 
> > But then there the following possibilities
> > 
> > (setq-default fill-column 72)
> > 
> > and
> > 
> > (add-hook 'prog-mode-hook (lambda () (setq fill-column 72)))
> > 
> > The first sets fill-column globally.
> 
> 
> It sets a default value, which is a different instance than any of
> the buffer local instances. ("Instance" is not strictly the
> correct term, but I'm trying it on.)
> 
> > What does that mean? I interpret that the value is set globally
> > but only to those buffers for which there is no local binding.
> 
> 
> It doesn't set anything for a buffer. It sets the default
> instance. Any buffer that lacks a local instance will use that
> default instance. Any local instance created after that will
> default to the value of that default instance.
> 
> > This setting the value (setq-default fill-column 72) does not
> > always work for the current buffer.
> 
> 
> It's not really doing anything to any buffer. It's doing something
> to the default instance. The question of which buffers (if any)
> use that instance is separate.
> 
> > How can one solve this problem?
> 
> 
> If you want to set the current buffer's value, use setq.
> 
> > What does the mode hook do exactly?
> 
> 
> When you enter a mode derived from prog-mode, it will set
> fill-column to 72, which for that variable creates a buffer local
> instance of it (and sets that instance). - Joel

It acts like a global setting for all prog-mode derived buffers,
rather than having to use setq on the buffer.

To have the local value for emacs-lisp-mode, one would do

(add-hook 'emacs-lisp-mode-hook (lambda () (setq fill-column 72)))

Is this how the local values for emacs-lisp-mode is set by emacs?

How can one make fill-column be 72 for all modes?  Is this possible?

  




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

* Re: fill-column setq-default and add-hook
  2024-12-04 12:39   ` Heime via Users list for the GNU Emacs text editor
@ 2024-12-05  1:46     ` Joel Reicher
  0 siblings, 0 replies; 4+ messages in thread
From: Joel Reicher @ 2024-12-05  1:46 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

Heime <heimeborgia@protonmail.com> writes:

> On Thursday, December 5th, 2024 at 12:00 AM, Joel Reicher 
> <joel.reicher@gmail.com> wrote:

[...]

>> When you enter a mode derived from prog-mode, it will set 
>> fill-column to 72, which for that variable creates a buffer 
>> local instance of it (and sets that instance).
>
> It acts like a global setting for all prog-mode derived buffers, 
> rather than having to use setq on the buffer.

But it is using setq on that buffer, albeit automatically, which 
is important.

> To have the local value for emacs-lisp-mode, one would do
>
> (add-hook 'emacs-lisp-mode-hook (lambda () (setq fill-column 
> 72)))
>
> Is this how the local values for emacs-lisp-mode is set by 
> emacs?

I'm not sure what you mean by emacs-lisp-mode having local values 
(or any values).

*Buffers* have local values, and you can use the activation of a 
 particular mode to automatically set these. But if you then 
 manually change modes in such a buffer the value will remain 
 (unless another mechanism changes it) so it isn't really 
 associated with the mode, and never was.

> How can one make fill-column be 72 for all modes?  Is this 
> possible?

You can use setq-default to set the default value for all buffers 
(not modes), and make sure you have nothing changing this again or 
creating buffer local instances that might have different values.

Cheers,

        - Joel



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

end of thread, other threads:[~2024-12-05  1:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-30 17:38 fill-column setq-default and add-hook Heime via Users list for the GNU Emacs text editor
2024-12-04 12:00 ` Joel Reicher
2024-12-04 12:39   ` Heime via Users list for the GNU Emacs text editor
2024-12-05  1:46     ` Joel Reicher

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