emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Condider adding buffer-mode


From: Bozhidar Batsov
Subject: Re: Condider adding buffer-mode
Date: Tue, 29 Oct 2013 17:53:17 +0200

On 25 October 2013 00:46, Stefan Monnier <address@hidden> wrote:
> 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. 

Another example would be selecting all buffers that have some major mode - maybe you want to enable something in all active elisp buffers, etc.
 
> Why don’t we add the following function to Emacs and simplify a bit
> the lives of Elisp hackers:

> (defun buffer-mode (buffer) "Return the major mode associated with BUFFER."
> (buffer-local-value ‘major-mode buffer))

Most uses of `major-mode' are better replaced with derived-mode-p, so
I don't think we just want to provide `buffer-mode'.

derived-mode-p works well for the current buffer, but it's not particularly useful if you want to do a mode check on other buffers as you'll still have to use `with-current-buffer'. I don't see how having something like `buffer-mode' would be a bad thing for Emacs hackers.
 


        Stefan



--
Best Regards,
Bozhidar Batsov

http://www.batsov.com

reply via email to

[Prev in Thread] Current Thread [Next in Thread]