unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Barry OReilly <gundaetiapo@gmail.com>
To: Ryan <rct@thompsonclan.org>
Cc: emacs-devel@gnu.org
Subject: Re: Improvements to adjust-parens
Date: Tue, 26 Nov 2013 18:04:54 -0500	[thread overview]
Message-ID: <CAFM41H3LtxeZfnr6MJ5gk2c3a09T6889LW-w-BO-udL1gmPa8w@mail.gmail.com> (raw)
In-Reply-To: <52944653.9000500@thompsonclan.org>

[-- Attachment #1: Type: text/plain, Size: 3391 bytes --]

       (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 <backtab> 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 perspective
about how people use <backtab>.

+(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 "<backtab>") '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)

[-- Attachment #2: Type: text/html, Size: 3878 bytes --]

  reply	other threads:[~2013-11-26 23:04 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <5293C972.2020605@thompsonclan.org>
2013-11-26  1:51 ` Improvements to adjust-parens Barry OReilly
2013-11-26  1:52   ` Ryan
2013-11-26  2:26   ` Stefan Monnier
2013-11-26  6:57   ` Ryan
2013-11-26 23:04     ` Barry OReilly [this message]
2013-11-27  1:04       ` Ryan C. Thompson
2013-11-27 20:00         ` Barry OReilly

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAFM41H3LtxeZfnr6MJ5gk2c3a09T6889LW-w-BO-udL1gmPa8w@mail.gmail.com \
    --to=gundaetiapo@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=rct@thompsonclan.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).