2

The problem occurs when customizing options in Emacs. Every time I click on a link a new buffer is created. How to force Emacs to use single buffer?

Luke Girvin
  • 13,221
  • 9
  • 64
  • 84
hks
  • 757
  • 1
  • 6
  • 13

2 Answers2

0

Try this:

(defadvice custom-buffer-create (before my-advice-custom-buffer-create)
  "Exit the current Customize buffer before creating a new one, unless there are modified widgets."
  (if (eq major-mode 'Custom-mode)
      (let ((custom-buffer-done-kill t)
            (custom-buffer-modified nil))
        (mapc (lambda (widget)
                (and (not custom-buffer-modified)
                     (eq (widget-get widget :custom-state) 'modified)
                     (setq custom-buffer-modified t)))
              custom-options)
        (if (not custom-buffer-modified)
            (Custom-buffer-done)))))
(ad-activate 'custom-buffer-create)
phils
  • 71,335
  • 11
  • 153
  • 198
  • edit: changed advice from `customize-group` to `custom-buffer-create`. – phils Feb 02 '11 at 03:00
  • 1
    Please take note that if you have not yet saved a change in your current Customize buffer, you will lose those edits when you change to a new buffer. – phils Feb 02 '11 at 03:07
  • Resolved the issue from the previous comment. Improvements to the code welcomed. – phils Feb 02 '11 at 22:12
  • That's exactly what I wanted. Thank you. As to ibuffer I don't find the need for it now as I'm emacs noobie. Maybe in the future. Thanks again. – hks Feb 04 '11 at 13:36
0

As an alternative to my original answer (which I am not inclined to use myself), I thought I might suggest other ways in which you might deal with getting rid of lots of Customize buffers once you have finished customising things.

First, do note that simply pressing q will "Exit current Custom buffer according to `custom-buffer-done-kill'" (i.e. either bury it or kill it).

Second is to use M-x kill-matching-buffers RET \*Customize RET (and then confirm each one), but that's a bit tedious.

What I'd actually do is use ibuffer.

If you don't use it already, I recommend binding C-x C-b to ibuffer, which is a greatly enhanced alternative to the default list-buffers. I love it primarily for its filtering and grouping abilities, but it can do a great deal besides that.

  (global-set-key (kbd "C-x C-b") 'ibuffer)

I also use the advice which can currently be found here at the Emacs Wiki so that ibuffer always opens with the buffer I came from selected.

That done, and from a Customize buffer, C-x C-b * M RET D y will kill all the Customize buffers. That is:

  • C-x C-b Open ibuffer (with point on the current Customize buffer entry)
  • * M Mark buffers by major mode...
  • RET ...select the mode (which defaulted to the major mode of the selected buffer, or otherwise type Custom-mode RET)
  • D y kill all marked buffers

Try it out; you'll probably like it. Searching for ibuffer will turn up other handy uses.

For instance, you could use / n ^\* RET / g tmp RET to separate out all buffers starting with * into a "tmp" group, so that they don't clutter up the group of buffers you are more likely to be interested in.

As with any major mode, use C-h m to read the built-in documentation.

Community
  • 1
  • 1
phils
  • 71,335
  • 11
  • 153
  • 198