From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Ryan C. Thompson" Newsgroups: gmane.emacs.devel Subject: Re: Improvements to adjust-parens Date: Tue, 26 Nov 2013 17:04:56 -0800 Message-ID: <52954538.50908@thompsonclan.org> References: <5293C972.2020605@thompsonclan.org> <52944653.9000500@thompsonclan.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1385514356 25435 80.91.229.3 (27 Nov 2013 01:05:56 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 27 Nov 2013 01:05:56 +0000 (UTC) Cc: emacs-devel@gnu.org To: Barry OReilly Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Nov 27 02:06:00 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 1VlTZn-0005Qk-Jm for ged-emacs-devel@m.gmane.org; Wed, 27 Nov 2013 02:05:59 +0100 Original-Received: from localhost ([::1]:33363 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VlTZm-0004jp-S1 for ged-emacs-devel@m.gmane.org; Tue, 26 Nov 2013 20:05:58 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42305) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VlTZb-0004ja-Gp for emacs-devel@gnu.org; Tue, 26 Nov 2013 20:05:54 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VlTZU-0001B6-6g for emacs-devel@gnu.org; Tue, 26 Nov 2013 20:05:47 -0500 Original-Received: from mail-pb0-f41.google.com ([209.85.160.41]:54458) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VlTZT-0001B1-Qx for emacs-devel@gnu.org; Tue, 26 Nov 2013 20:05:40 -0500 Original-Received: by mail-pb0-f41.google.com with SMTP id jt11so9279953pbb.0 for ; Tue, 26 Nov 2013 17:05:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=00SWXChE1tI9yUhQ5CsPSGdUfLNdSmlKmQsK6jT5bIo=; b=HagJ8FTFZht9ktyfJNBkO9eP3A00reZ+raLKCa99tY02eoZR66REC8KwQLyXjZnZfW vmmL20mgllv4QMVpNqWs0/mMlo1k1SozTgPFjthqGwsusDHvB79AivBKHeh5vrxSRCI3 R+Ti81IWo98diWxWe9GdM08H5HXX3UYSnXW8qkx5gFvJfyyJM+PhZg7M8GrwENCkkuM+ HV/UOZ0B44CeSS7wnr8PvmFVZWYnEC93TnpGMRE7XiuVJKKE02TGILYVoR+0cngkBQVJ U9HFYNdgu1/AvZOgZTdz+113H60T5If4OWM1NcjmJBjIKoJpFWgh88S6JFaJ/yGpgyHL ZzpA== X-Gm-Message-State: ALoCoQlF3wDi8Je4+exem8p4KaELf+CHIGqJNo/vM/JCzyDDbBJPWHG5o57q91pnmICKz8Z2ivCb X-Received: by 10.68.231.68 with SMTP id te4mr2269596pbc.174.1385514338771; Tue, 26 Nov 2013 17:05:38 -0800 (PST) Original-Received: from [137.131.89.60] (salomon14.scripps.edu. [137.131.89.60]) by mx.google.com with ESMTPSA id qz9sm82355323pbc.3.2013.11.26.17.05.37 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 26 Nov 2013 17:05:37 -0800 (PST) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.1 In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.160.41 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:165795 Archived-At: Replies in line below: On 11/26/2013 03:04 PM, Barry OReilly wrote: > (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)))))))) > Sounds good. Also change "corrent" to "current". That's probably a typo on my part. > 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. I believe the "C-u" prefix is passed as a list just so you can tell the difference between e.g. "C-4" and "C-u", i.e. a numeric vs generic prefix argument. I don't think there is ever more than one element in the list. In any case, you can make the prefix arguments work however you want. > > + (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)) That's fine. I just did the first thing that worked. > > + ;; 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 . I forget what my logic was here. Feel free to do whatever you think is appropriate. I think backtab is actually not used in many modes. > > +(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) > The global mode isn't really "global". It only activates in buffers with approved major modes. This is essentially a way for users who do all their customization through M-x customize to auto-enable adjust-parens in specific modes, by enabling the global mode and then customizing "adjust-parens-enabled-major-modes".