From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Bozhidar Batsov Newsgroups: gmane.emacs.devel Subject: Re: Condider adding buffer-mode Date: Tue, 29 Oct 2013 19:28:50 +0200 Message-ID: References: <859D68184C604AE8AC385A3C5255FDAA@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=089e01538848c75b7b04e9e48c69 X-Trace: ger.gmane.org 1383073537 1816 80.91.229.3 (29 Oct 2013 19:05:37 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 29 Oct 2013 19:05:37 +0000 (UTC) Cc: emacs-devel To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Oct 29 20:05:43 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1VbEbk-000723-AR for ged-emacs-devel@m.gmane.org; Tue, 29 Oct 2013 20:05:40 +0100 Original-Received: from localhost ([::1]:48890 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VbEbj-0003tq-FV for ged-emacs-devel@m.gmane.org; Tue, 29 Oct 2013 15:05:39 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39562) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VbD65-0002PS-A6 for emacs-devel@gnu.org; Tue, 29 Oct 2013 13:28:54 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VbD63-0004ob-EC for emacs-devel@gnu.org; Tue, 29 Oct 2013 13:28:53 -0400 Original-Received: from mail-ob0-x22a.google.com ([2607:f8b0:4003:c01::22a]:63239) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VbD63-0004oV-77 for emacs-devel@gnu.org; Tue, 29 Oct 2013 13:28:51 -0400 Original-Received: by mail-ob0-f170.google.com with SMTP id wp18so218383obc.1 for ; Tue, 29 Oct 2013 10:28:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=EqE9FYYg2iZwx/wLoc0Wg8Bz0iqiOgnsAO8EgmrnpS0=; b=v8vSkExr7laojblhNtcreVo3TpOZ+tus0+08xrK34xhEEKR0ObPW5y+Ph4u8lAuKzF +o/6zmvJC2p2jrNWXQtLcOOv5dL/h+DE3Xy+joTYbteTDCGMsjORkDrqfKtkILhPVYe7 V8L50FGwoHKdMeTkchREdrNf0mx67WCl1iwH2SBe7fkVWVrcKhCTs1dtoA/FOm5cBY/z Wu2RMyJnnEnlbgewOdslLxp0VHp+XGYqkhG+ooBrnK4xJrtDsOJh9HRuNF9+MAi2/BG3 AzEuNwC20e9zl2LwDCjJcw6vq+iXy/OXkdaSm429U+cS9JI0APt6w+4twiO0hBbokbmV qs5g== X-Received: by 10.182.55.65 with SMTP id q1mr572111obp.2.1383067730531; Tue, 29 Oct 2013 10:28:50 -0700 (PDT) Original-Received: by 10.76.131.116 with HTTP; Tue, 29 Oct 2013 10:28:50 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4003:c01::22a X-Mailman-Approved-At: Tue, 29 Oct 2013 15:05:34 -0400 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:164650 Archived-At: --089e01538848c75b7b04e9e48c69 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Here's some real examples: (defun cider-util--clojure-buffers () "Return a list of all existing `clojure-mode' buffers." (-filter (lambda (buffer) (eq 'clojure-mode (buffer-local-value 'major-mode buffer))) (buffer-list))) vs (defun cider-util--clojure-buffers () "Return a list of all existing `clojure-mode' buffers." (-filter (lambda (buffer) (eq 'clojure-mode (buffer-mode buffer))) (buffer-list))) =3D=3D=3D (defun cider-remember-clojure-buffer (buffer) "Try to remember the BUFFER from which the user jumps. The BUFFER needs to be a Clojure buffer and current major mode needs to be `cider-repl-mode'. The user can use `cider-switch-to-last-clojure-buffer' to jump back to the last Clojure source buffer." (when (and buffer (eq 'clojure-mode (with-current-buffer buffer major-mode)) (eq 'cider-repl-mode major-mode)) (setq cider-last-clojure-buffer buffer))) vs (defun cider-remember-clojure-buffer (buffer) "Try to remember the BUFFER from which the user jumps. The BUFFER needs to be a Clojure buffer and current major mode needs to be `cider-repl-mode'. The user can use `cider-switch-to-last-clojure-buffer' to jump back to the last Clojure source buffer." (when (and buffer (eq 'clojure-mode (buffer-mode buffer)) (eq 'cider-repl-mode major-mode)) (setq cider-last-clojure-buffer buffer))) Seems to me `buffer-mode' makes the code clearer, but that's subjective (as most things in life :-) ) On 29 October 2013 18:36, Stefan Monnier wrote: > >> > I=E2=80=99ve seen the following code used hundreds of times: > >> > (buffer-local-value 'major-mode buffer) > >> > or > >> > (with-current-buffer buffer =E2=80=98major-mode) > >> Where? > > One example would be packages like SLIME and CIDER which feature comman= ds > > 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 thi= s. > > 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 mod= e > - > > 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 > > or maybe > > (dolist (buf (buffer-list)) > (when (eq 'foo-mode (buffer-mode buf)) > (with-current-buffer buf > > neither of which seems any better than: > > (dolist (buf (buffer-list)) > (with-current-buffer buf > (when (derived-mode-p 'foo-mode) > > > 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 > --=20 Best Regards, Bozhidar Batsov http://www.batsov.com --089e01538848c75b7b04e9e48c69 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Here's some real examples:

(defun cider-util--clojure-buffers ()
=C2=A0 "Return a li= st of all existing `clojure-mode' buffers."
=C2=A0 (-fil= ter
=C2=A0 =C2=A0(lambda (buffer) (eq 'clojure-mode (buffer-local-valu= e 'major-mode buffer)))
=C2=A0 =C2=A0(buffer-list)))

vs

(defun cider-util--clojur= e-buffers ()
=C2=A0 "Return a list of all existing `clojure-mode' buffers.= "
=C2=A0 (-filter
=C2=A0 =C2=A0(lambda (buffer) (e= q 'clojure-mode (buffer-mode buffer)))
=C2=A0 =C2=A0(buffer-l= ist)))

=3D=3D=3D

(defun cider-remember-cl= ojure-buffer (buffer)
=C2=A0 "Try to remember the BUFFER fro= m which the user jumps.
The BUFFER needs to be a Clojure buffer a= nd current major mode needs
to be `cider-repl-mode'. =C2=A0The user can use `cider-switch-to-l= ast-clojure-buffer'
to jump back to the last Clojure source b= uffer."
=C2=A0 (when (and buffer
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(eq 'clojure-mode (with-current-buffer b= uffer major-mode))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(eq 'cider-repl-mo= de major-mode))
=C2=A0 =C2=A0 (setq cider-last-clojure-buffer buf= fer)))

vs

(defun cider-remember-clojure-buffer (buffer)
=C2=A0 "Try to remember the BUFFER from which the user jumps.
The BUFFER needs to be a Clojure buffer and current major mode needs=
to be `cider-repl-mode'. =C2=A0The user can use `cider-switc= h-to-last-clojure-buffer'
to jump back to the last Clojure source buffer."
=C2=A0= (when (and buffer
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0(eq 'clojure-mode (buffer-mode buffer))
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(eq 'cider-repl-mode major-mode))
=C2=A0 =C2=A0 (setq cider-last-clojure-buffer buffer)))

Seems to me `buffer-mode' makes the code clearer= , but that's subjective (as most things in life :-) )




On 29 October 2013 18:36, Stefan Monnier <monnier@iro.umontrea= l.ca> wrote:
>> > I=E2=80=99ve= seen the following code used hundreds of times:
>> > (buffer-local-value 'major-mode buffer)
>> > or
>> > (with-current-buffer buffer =E2=80=98major-mode)
>> Where?
> One example would be packages like SLIME and CIDER which feature comma= nds
> that operate in a different manner when invoked in a REPL or a lisp bu= ffer.
> Obviously one could have written different commands for the different<= br> > modes, but that doesn't change the fact that people write code lik= e this.

This sounds like they check `major-mode', but in the current buff= er, so
they wouldn't need something like `buffer-mode'.

> Another example would be selecting all buffers that have some major mo= de -
> 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:

=C2=A0 =C2=A0(dolist (buf (cl-remove-if-not (lambda (x) (eq 'foo-mode (= buffer-mode x)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (buffer-list)))
=C2=A0 =C2=A0 =C2=A0(with-current-buffer buf
=C2=A0 =C2=A0 =C2=A0 =C2=A0<do-something))

or maybe

=C2=A0 =C2=A0(dolist (buf (buffer-list))
=C2=A0 =C2=A0 =C2=A0(when (eq 'foo-mode (buffer-mode buf))
=C2=A0 =C2=A0 =C2=A0 =C2=A0(with-current-buffer buf
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0<do-something)))

neither of which seems any better than:

=C2=A0 =C2=A0(dolist (buf (buffer-list))
=C2=A0 =C2=A0 =C2=A0(with-current-buffer buf
=C2=A0 =C2=A0 =C2=A0 =C2=A0(when (derived-mode-p 'foo-mode)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0<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 u= se 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 "some= thing like
buffer-mode".


=C2=A0 =C2=A0 =C2=A0 =C2=A0 Stefan



--
Best Regards,
Bozhidar Batsov

--089e01538848c75b7b04e9e48c69--