all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Changing side margins in specific mode changes side margins for all buffers
@ 2015-06-15 22:29 hack writer
  2015-06-16 21:47 ` hack writer
       [not found] ` <mailman.5129.1434491234.904.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 6+ messages in thread
From: hack writer @ 2015-06-15 22:29 UTC (permalink / raw
  To: help-gnu-emacs

Hi everyone,

I use

(add-hook 'window-configuration-change-hook (lambda () (set-window-margins
(car (get-buffer-window-list (current-buffer) nil t)) 29 29)))

to set side margins in a specific emacs mode. But when I open further
buffers, no matter what mode, all buffers use the same side margins. How I
can achieve, that only my specific mode buffers use side margins but all
other buffers not?

(add-hook 'window-configuration-change-hook (lambda () (set-window-margins
(car (get-buffer-window-list (current-buffer) nil t)) 29 29))
'make-it-local)

didn't work.

Regards

hack





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

* Re: Changing side margins in specific mode changes side margins for all buffers
       [not found] <mailman.5065.1434407365.904.help-gnu-emacs@gnu.org>
@ 2015-06-15 23:04 ` Emanuel Berg
  2015-06-16  1:13 ` Stefan Monnier
  1 sibling, 0 replies; 6+ messages in thread
From: Emanuel Berg @ 2015-06-15 23:04 UTC (permalink / raw
  To: help-gnu-emacs

hack writer <GNU@bookhacker.org> writes:

> (add-hook 'window-configuration-change-hook (lambda
> () (set-window-margins (car (get-buffer-window-list
> (current-buffer) nil t)) 29 29)))
>
> to set side margins in a specific emacs mode.
> But when I open further buffers, no matter what
> mode, all buffers use the same side margins.
> How I can achieve, that only my specific mode
> buffers use side margins but all other buffers not?
>
> (add-hook 'window-configuration-change-hook (lambda
> () (set-window-margins (car (get-buffer-window-list
> (current-buffer) nil t)) 29 29)) 'make-it-local)
>
> didn't work.

No - this whole idea isn't good. It will slow down the
interactive feel to test at each window configuration
change what mode it is. And the "slowing down" is
going in the wrong direction - something specific
(your mode) will slow down all of Emacs!

What kind of mode do you have? I think there is a much
better way to do this, but it is difficult to tell
without knowing what you want to do.

-- 
underground experts united
http://user.it.uu.se/~embe8573


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

* Re: Changing side margins in specific mode changes side margins for all buffers
       [not found] <mailman.5065.1434407365.904.help-gnu-emacs@gnu.org>
  2015-06-15 23:04 ` Emanuel Berg
@ 2015-06-16  1:13 ` Stefan Monnier
  2015-06-17  0:58   ` Emanuel Berg
  1 sibling, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2015-06-16  1:13 UTC (permalink / raw
  To: help-gnu-emacs

> (add-hook 'window-configuration-change-hook (lambda () (set-window-margins
> (car (get-buffer-window-list (current-buffer) nil t)) 29 29)))

Your code is unreadable.  For your own sake, lay it out clearly:

   (add-hook 'window-configuration-change-hook
             (lambda ()
               (set-window-margins (car (get-buffer-window-list
                                         (current-buffer) nil t))
                                   29 29)))

Which sets up a global hook, and then

> (add-hook 'window-configuration-change-hook (lambda () (set-window-margins
> (car (get-buffer-window-list (current-buffer) nil t)) 29 29))
> 'make-it-local)

turns into

   (add-hook 'window-configuration-change-hook
             (lambda ()
               (set-window-margins (car (get-buffer-window-list
                                         (current-buffer) nil t))
                                   29 29))
             'make-it-local)

where you see that you pass `make-it-local' as third argument.  And if
you check `C-h f add-hook RET' you'll see that the third arg is called
APPEND, and it's the *fourth* arg which is called LOCAL.  So you just
need to add a nil as third argument.

BTW, where did you get (car (get-buffer-window-list (current-buffer) nil t))?
`C-h v window-configuration-change-hook' says:

   The buffer-local part is run once per window, with the relevant window
   selected; while the global part is run only once for the modified frame,

so since "the relevant window" is already selected, you don't need to
look for it.  You can either use (selected-window) or more simply nil
since the default for set-window-margins is to use the selected window.

IOW:

   (add-hook 'window-configuration-change-hook
             (lambda () (set-window-margins nil 29 29))
             nil 'local)


-- Stefan


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

* Re: Changing side margins in specific mode changes side margins for all buffers
  2015-06-15 22:29 Changing side margins in specific mode changes side margins for all buffers hack writer
@ 2015-06-16 21:47 ` hack writer
       [not found] ` <mailman.5129.1434491234.904.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 6+ messages in thread
From: hack writer @ 2015-06-16 21:47 UTC (permalink / raw
  To: help-gnu-emacs

@Stefan

Works like a charm. Thank you very much!

I found this code somewhere on stackoverflow.com.

Regards,

hack



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

* Re: Changing side margins in specific mode changes side margins for all buffers
       [not found] ` <mailman.5129.1434491234.904.help-gnu-emacs@gnu.org>
@ 2015-06-16 22:35   ` Stefan Monnier
  0 siblings, 0 replies; 6+ messages in thread
From: Stefan Monnier @ 2015-06-16 22:35 UTC (permalink / raw
  To: help-gnu-emacs

> Works like a charm. Thank you very much!
> I found this code somewhere on stackoverflow.com.

Could you try and find it again, so we can fix it there?


        Stefan


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

* Re: Changing side margins in specific mode changes side margins for all buffers
  2015-06-16  1:13 ` Stefan Monnier
@ 2015-06-17  0:58   ` Emanuel Berg
  0 siblings, 0 replies; 6+ messages in thread
From: Emanuel Berg @ 2015-06-17  0:58 UTC (permalink / raw
  To: help-gnu-emacs

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>    (add-hook 'window-configuration-change-hook
>              (lambda ()
>                (set-window-margins (car (get-buffer-window-list
>                                          (current-buffer) nil t))
>                                    29 29))
>              'make-it-local)
>
> where you see that you pass `make-it-local' as third
> argument. And if you check `C-h f add-hook RET'
> you'll see that the third arg is called APPEND, and
> it's the *fourth* arg which is called LOCAL. So you
> just need to add a nil as third argument.

Aha, the HOOK is local, not the window-margins!
Then what I said is incorrect. It won't do what I said
(which is good).

>> Works like a charm. Thank you very much! I found
>> this code somewhere on stackoverflow.com.
>
> Could you try and find it again, so we can fix
> it there?

Wow, you are dedicated! Cred. Maybe we should all post
our Elisp on stackoverflow just to have you correct it
:)

-- 
underground experts united
http://user.it.uu.se/~embe8573


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

end of thread, other threads:[~2015-06-17  0:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-15 22:29 Changing side margins in specific mode changes side margins for all buffers hack writer
2015-06-16 21:47 ` hack writer
     [not found] ` <mailman.5129.1434491234.904.help-gnu-emacs@gnu.org>
2015-06-16 22:35   ` Stefan Monnier
     [not found] <mailman.5065.1434407365.904.help-gnu-emacs@gnu.org>
2015-06-15 23:04 ` Emanuel Berg
2015-06-16  1:13 ` Stefan Monnier
2015-06-17  0:58   ` Emanuel Berg

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.