[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Condider adding buffer-mode
From: |
Stefan Monnier |
Subject: |
Re: Condider adding buffer-mode |
Date: |
Tue, 29 Oct 2013 12:36:44 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) |
>> > I’ve seen the following code used hundreds of times:
>> > (buffer-local-value 'major-mode buffer)
>> > or
>> > (with-current-buffer buffer ‘major-mode)
>> Where?
> One example would be packages like SLIME and CIDER which feature commands
> that operate in a different manner when invoked in a REPL or a lisp buffer.
> Obviously one could have written different commands for the different
> modes, but that doesn't change the fact that people write code like this.
This sounds like they check `major-mode', but in the current buffer, so
they wouldn't need something like `buffer-mode'.
> Another example would be selecting all buffers that have some major mode -
> maybe you want to enable something in all active elisp buffers, etc.
Can you point out actual code?
I'm not saying it doesn't exist, I'm just failing to understand why
`buffer-mode' would be useful for those cases.
E.g. using buffer-mode, I guess I'd write a loop like:
(dolist (buf (cl-remove-if-not (lambda (x) (eq 'foo-mode (buffer-mode x)))
(buffer-list)))
(with-current-buffer buf
<do-something))
or maybe
(dolist (buf (buffer-list))
(when (eq 'foo-mode (buffer-mode buf))
(with-current-buffer buf
<do-something)))
neither of which seems any better than:
(dolist (buf (buffer-list))
(with-current-buffer buf
(when (derived-mode-p 'foo-mode)
<do-something)))
> I don't see how having something like `buffer-mode' would be a bad
> thing for Emacs hackers.
I'm not saying it's bad, but I'd like to see compelling use cases first.
BTW, when I said:
> I don't think we just want to provide `buffer-mode'.
I really meant "just buffer-mode", as opposed to "something like
buffer-mode".
Stefan
- Condider adding buffer-mode, Bozhidar Batsov, 2013/10/24
- Re: Condider adding buffer-mode, Stefan Monnier, 2013/10/24
- Re: Condider adding buffer-mode, Bozhidar Batsov, 2013/10/29
- Re: Condider adding buffer-mode,
Stefan Monnier <=
- Re: Condider adding buffer-mode, Bozhidar Batsov, 2013/10/29
- Re: Condider adding buffer-mode, Stefan Monnier, 2013/10/29
- Re: Condider adding buffer-mode, Bozhidar Batsov, 2013/10/30
- Re: Condider adding buffer-mode, Stefan Monnier, 2013/10/30
- Re: Condider adding buffer-mode, Bozhidar Batsov, 2013/10/31