From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Barry OReilly Newsgroups: gmane.emacs.devel Subject: Re: Improvements to adjust-parens Date: Tue, 26 Nov 2013 18:04:54 -0500 Message-ID: References: <5293C972.2020605@thompsonclan.org> <52944653.9000500@thompsonclan.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=089e013cba6234813704ec1c82dc X-Trace: ger.gmane.org 1385507100 15959 80.91.229.3 (26 Nov 2013 23:05:00 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 26 Nov 2013 23:05:00 +0000 (UTC) Cc: emacs-devel@gnu.org To: Ryan Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Nov 27 00:05:03 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 1VlRgj-0004mX-Gh for ged-emacs-devel@m.gmane.org; Wed, 27 Nov 2013 00:05:01 +0100 Original-Received: from localhost ([::1]:33102 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VlRgj-0001Ei-1Z for ged-emacs-devel@m.gmane.org; Tue, 26 Nov 2013 18:05:01 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52740) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VlRge-0001EW-QV for emacs-devel@gnu.org; Tue, 26 Nov 2013 18:04:57 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VlRgd-00018S-K8 for emacs-devel@gnu.org; Tue, 26 Nov 2013 18:04:56 -0500 Original-Received: from mail-ob0-x233.google.com ([2607:f8b0:4003:c01::233]:52393) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VlRgd-00018J-DF for emacs-devel@gnu.org; Tue, 26 Nov 2013 18:04:55 -0500 Original-Received: by mail-ob0-f179.google.com with SMTP id wm4so6558448obc.38 for ; Tue, 26 Nov 2013 15:04:54 -0800 (PST) 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=05yiQfLupu/ClxOF3kXPbhQVXJ4sy5gm5JDPsVQ8FfY=; b=Us+bYDsOzY0U6LJYuOvANXV9241lCAndKBbQ6ANF/lqBtbAiNZWiuv5zW5jpt/yE1I B9eWfQtk3WPOmJxHbYwlBLWQl3S/JJfVVz5BgvyvTXdLmsgNnJNgPHhRe8uyrP5tV9K0 lm83Ppd8VMW/OAQCBiacKkKt0B4O7ejwNmW73wOJjsMzRUDsD4qTmVG+noW7HuLRfFYV +OxPdk4IDNHrlPnD61Dl4CEs/f9WtIbcIrD0WL2weCzyUHPV8YmNrw3l1sSiRWVCUg+X kpOe+bVMAoA3vnCofRY2rkArzW49RY0MJD9r10mxx/xJklQ4kjHzESu3KSK57DfSX26m OnwA== X-Received: by 10.182.87.42 with SMTP id u10mr31562113obz.22.1385507094559; Tue, 26 Nov 2013 15:04:54 -0800 (PST) Original-Received: by 10.76.156.103 with HTTP; Tue, 26 Nov 2013 15:04:54 -0800 (PST) In-Reply-To: <52944653.9000500@thompsonclan.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4003:c01::233 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:165792 Archived-At: --089e013cba6234813704ec1c82dc Content-Type: text/plain; charset=ISO-8859-1 (and (not (use-region-p)) - (<= orig-pos (point)))))) + ;; Corrent line is properly indented + (= (current-column) + (let ((indent (calculate-lisp-indent))) + (if (listp indent) + (car indent) + indent))) + ;; Point at indentation + (= orig-pos (point)))))) Revising the diff to account for nil indent and to put the most expensive check last: - (and (not (use-region-p)) - (<= orig-pos (point)))))) + (and (= orig-pos (point)) + (not (use-region-p)) + ;; Corrent line is properly indented + (let ((indent (calculate-lisp-indent))) + (and indent + (= (current-column) + (if (listp indent) + (car indent) + indent)))))))) Regarding: + ;; Only pass an explicit numeric prefix, not `C-u' prefix. + (unless (listp parg) + (prefix-numeric-value parg))) What sort of use cases do prefix args as lists normally serve? From what I see, they come in powers of four, which doesn't seem applicable to adjust-parens. The Elisp manual entry doesn't really cover the "why" of this kind of prefix arg. + (cl-callf or parg 1) + ;; Negative prefix arg inverts the behavior + (when (< parg 0) + (setq parg (- parg) + adjust-function + (cl-case adjust-function + (adjust-close-paren-for-indent 'adjust-close-paren-for-dedent) + (adjust-close-paren-for-dedent 'adjust-close-paren-for-indent) + (otherwise (error "Unknown adjust-function: %s" adjust-function))))) + (when (> parg 0) Processing negative prefix arg makes sense. I think it is cleaner to do it one level higher and pass the right function as the adjust-function argument. eg: (adjust-parens-and-indent (if (< parg 0) 'adjust-close-paren-for-dedent 'adjust-close-paren-for-indent) (abs parg)) + ;; Move forward (but not back) to end of indentation (but don't + ;; change the indentation unlike `indent-for-tab-command'. + (when (< (current-column) (current-indentation)) + (back-to-indentation)))) I figured since is unbound in 'emacs -Q', adjust-parens should do nothing in this case. The analogous in Python appears to also do nothing if it does not dedent. It might be easier to decide what to do here with better perspective about how people use . +(define-globalized-minor-mode global-adjust-parens-mode adjust-parens-mode (lambda () - (local-set-key (kbd "TAB") 'lisp-indent-adjust-parens) - (local-set-key (kbd "") 'lisp-dedent-adjust-parens))) + ;; Add or remove hook + (funcall (if global-adjust-parens-mode #'add-hook #'remove-hook) + 'after-change-major-mode-hook + #'adjust-parens-after-change-mm-hook) + ;; Run the hook in existing buffers to enable/disable the mode + (dolist (buf (buffer-list)) + (with-current-buffer buf + (adjust-parens-after-change-mm-hook))))) adjust-parens doesn't seem global in nature, so I'm uncertain about the choice of a global minor mode. I think a local minor mode makes sense though. Then the user would enable it in major modes by eg: (add-hook 'emacs-lisp-mode-hook #'adjust-parens-mode) --089e013cba6234813704ec1c82dc Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
=A0=A0=A0=A0=A0=A0 (and (not (use-region-p))
-=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0 (<=3D orig-pos (point))))))
+=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0 ;; Corrent line is properly indented
+=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0 (=3D (current-column)
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= (let ((indent (calculate-lisp-indent)))
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (if (listp indent)
+=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (car indent)
+=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 indent)))
+=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0 ;; Point at indentation
+=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0 (=3D orig-pos (point))))))

Revising the diff to account for nil = indent and to put the most
expensive check last:

-=A0=A0=A0=A0=A0 (and (not (use-region-p))
= -=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (<=3D orig-pos (point))))))
+=A0=A0= =A0=A0=A0 (and (=3D orig-pos (point))
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (n= ot (use-region-p))
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ;; Corrent line is pr= operly indented
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (let ((indent (calculate-lisp-indent)))
= +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (and indent
+=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (=3D (current-column)
+=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (if (listp indent)
+=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (car indent= )
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 in= dent))))))))

Regarding:

+=A0=A0=A0=A0=A0=A0 ;; Only pass an explicit numeric = prefix, not `C-u' prefix.
+=A0=A0=A0=A0=A0=A0 (unless (listp parg)+=A0=A0=A0=A0=A0=A0=A0=A0 (prefix-numeric-value parg)))

What sort = of use cases do prefix args as lists normally serve? From
what I see, they come in powers of four, which doesn't seem applicable<= br>to adjust-parens. The Elisp manual entry doesn't really cover the"why" of this kind of prefix arg.

+=A0 (cl-callf or parg = 1)
+=A0 ;; Negative prefix arg inverts the behavior
+=A0 (when (< parg 0= )
+=A0=A0=A0 (setq parg (- parg)
+=A0=A0=A0=A0=A0=A0=A0=A0=A0 adjust-= function
+=A0=A0=A0=A0=A0=A0=A0=A0=A0 (cl-case adjust-function
+=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (adjust-close-paren-for-indent 'adjust-c= lose-paren-for-dedent)
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (adjust-close-paren-for-dedent 'adju= st-close-paren-for-indent)
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (otherwise= (error "Unknown adjust-function: %s" adjust-function)))))
+= =A0 (when (> parg 0)

Processing negative prefix arg makes sense. = I think it is cleaner to
do it one level higher and pass the right function as the
adjust-functio= n argument. eg:

=A0 (adjust-parens-and-indent
=A0=A0 (if (< pa= rg 0)
=A0=A0=A0=A0=A0=A0 'adjust-close-paren-for-dedent
=A0=A0=A0= =A0 'adjust-close-paren-for-indent)
=A0=A0 (abs parg))

+=A0=A0=A0 ;; Move forward (but not back) to end = of indentation (but don't
+=A0=A0=A0 ;; change the indentation unlik= e `indent-for-tab-command'.
+=A0=A0=A0 (when (< (current-column) = (current-indentation))
+=A0=A0=A0=A0=A0 (back-to-indentation))))

I figured since <backta= b> is unbound in 'emacs -Q', adjust-parens
should do nothing = in this case. The analogous <backtab> in Python
appears to also do= nothing if it does not dedent.

It might be easier to decide what to do here with better perspectiveabout how people use <backtab>.

+(define-globalized-minor-mod= e global-adjust-parens-mode adjust-parens-mode
=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0 (lambda ()
-=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (local-set-key (kbd "TAB") = 9;lisp-indent-adjust-parens)
-=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (local-s= et-key (kbd "<backtab>") 'lisp-dedent-adjust-parens)))<= br>+=A0=A0=A0 ;; Add or remove hook
+=A0=A0=A0 (funcall (if global-adjus= t-parens-mode #'add-hook #'remove-hook)
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 'after-change-major-mode-hook
= +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 #'adjust-parens-after-change-mm-h= ook)
+=A0=A0=A0 ;; Run the hook in existing buffers to enable/disable th= e mode
+=A0=A0=A0 (dolist (buf (buffer-list))
+=A0=A0=A0=A0=A0 (with-= current-buffer buf
+=A0=A0=A0=A0=A0=A0=A0 (adjust-parens-after-change-mm-hook)))))

adju= st-parens doesn't seem global in nature, so I'm uncertain about
= the choice of a global minor mode. I think a local minor mode makes
sens= e though. Then the user would enable it in major modes by eg:

=A0 (add-hook 'emacs-lisp-mode-hook #'adjust-parens-mode)
--089e013cba6234813704ec1c82dc--