From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Teemu Likonen Newsgroups: gmane.emacs.devel Subject: More intelligent command for C-x TAB (understand also tab-stop-list) Date: Sat, 13 Jul 2013 09:41:58 +0300 Message-ID: <871u73hsg9.fsf@mithlond.arda> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" X-Trace: ger.gmane.org 1373697737 6897 80.91.229.3 (13 Jul 2013 06:42:17 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 13 Jul 2013 06:42:17 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Jul 13 08:42:16 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 1UxtX3-0004HC-Ur for ged-emacs-devel@m.gmane.org; Sat, 13 Jul 2013 08:42:14 +0200 Original-Received: from localhost ([::1]:37259 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UxtX3-0001GB-K5 for ged-emacs-devel@m.gmane.org; Sat, 13 Jul 2013 02:42:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40153) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UxtWy-0001G3-1k for emacs-devel@gnu.org; Sat, 13 Jul 2013 02:42:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UxtWv-00077l-0c for emacs-devel@gnu.org; Sat, 13 Jul 2013 02:42:07 -0400 Original-Received: from mta-out.inet.fi ([195.156.147.13]:36609 helo=jenni1.inet.fi) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UxtWu-00077I-LC for emacs-devel@gnu.org; Sat, 13 Jul 2013 02:42:04 -0400 Original-Received: from mithlond.arda (84.251.134.110) by jenni1.inet.fi (8.5.140.03) id 5163EC560693D8AF for emacs-devel@gnu.org; Sat, 13 Jul 2013 09:42:02 +0300 Original-Received: from dtw by mithlond.arda with local (Exim 4.80) (envelope-from ) id 1UxtWs-0001Cx-0q for emacs-devel@gnu.org; Sat, 13 Jul 2013 09:42:02 +0300 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 195.156.147.13 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:161848 Archived-At: --=-=-= Content-Type: text/plain I propose binding a new command to C-x TAB. This new command would have all the functionality of the current command (indent-rigidly) but also added intelligence to understand tab-stop-list. I have discussed this in #8196: . But as there was some misunderstanding I try to write a better explanation here. The current C-x TAB command (indent-rigidly) command moves region forward or backward by the number of columns given as prefix argument. If user does not give the command a prefix argument the default is to move by 1 column. My proposed new C-x TAB command would do the same thing as indent-rigidly when given a numeric prefix argument. There would be difference only when user doesn't give it a numeric prefix argument. In such case the new C-x TAB command would move the region to the next or previous tab stop as defined in the tab-stop-list variable. The lowest indentation level of the region would be moved to the tab stop column. Here's a concrete editing example. We have defined tab-stop-list variable as (4 8 12 16 20 etc.) and we have a buffer with the following text: (defun foo () (some-code) (more-code)) Now I mark the above piece of code with M-h and execute "M-x indent-rigidly". The result is this: (defun foo () (some-code) (more-code)) The text advances by one column. With my proposed new command it would move to the next tab stop column: (defun foo () (some-code) (more-code)) The lowest indentation point of that region is now at column 4 because that's the next tab stop defined in tab-stop-list variable. In my proposed new command there is a repeat feature too. If I keep on repeating TAB (that is, C-x TAB TAB TAB) the region would move to the next tab stops: 8, 12, 16, 20 etc. With the negative non-numeric prefix argument (C-u -) my proposed command would do the same but go to the previous tab stop column as defined in tab-stop-list variable. The name for this new command could be "indent-region-to-tab-stop", for example, and it relies on "indent-region" to do the actual job. For those who want to try this command just evaluate the code below. Emacs developers are free to use the code because I have done the copyright-assignment paperwork for FSF. --8<---------------cut here---------------start------------->8--- (defun region-indentation (beg end) "Return the smallest indentation in range from BEG to END. Blank lines are ignored." (save-excursion (let ((beg (progn (goto-char beg) (line-beginning-position))) indent) (goto-char beg) (while (re-search-forward "^\\s-*[[:print:]]" end t) (setq indent (min (or indent (current-indentation)) (current-indentation)))) indent))) (defun indent-region-to-tab-stop-engine (beg end arg) "Back-end function for `indent-region-to-tab-stop'." (interactive "r\nP") (let* ((beg (save-excursion (goto-char beg) (line-beginning-position))) (current (region-indentation beg end)) (indent (cond ((not arg) (- (catch 'answer (dolist (col tab-stop-list (1+ current)) (when (> col current) (throw 'answer col)))) current)) ((eq arg '-) (- (catch 'answer (dolist (col (reverse tab-stop-list) 0) (when (< col current) (throw 'answer col)))) current)) (t (prefix-numeric-value arg))))) (indent-rigidly beg end indent))) (defun indent-region-to-tab-stop (beg end arg) "Indent region to a tab stop column or to the specified column. Indent the region from BEG to END according to the command's prefix argument ARG. If ARG is nil (i.e., there is no prefix argument) indent the region to the next tab stop column in `tab-stop-list'. With negative prefix ARG (C-u -) indent the region to the previous tab stop column. If ARG is an integer indent the region by ARG columns (just like `indent-rigidly' command). If this command is invoked by a multi-character key sequence, it can be repeated by repeating the final character of the sequence." (interactive "r\nP") (require 'repeat) (let ((repeat-message-function 'ignore)) (setq last-repeatable-command 'indent-region-to-tab-stop-engine) (repeat nil))) --8<---------------cut here---------------end--------------->8--- --=-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iQIcBAEBCAAGBQJR4Pa2AAoJEHGdadMkU5RQF0oP/3b0GoRj/8V/uauxIWdrh9Wd P+mZBw7ViDD3tCKMimbj0zeLWfi+md/rkBDxP5ziOCCrWCWJFpwvVeJSnjFfb98D II4Ea14bMifDeF5hAroJoACs3oDCKu4NwBFjbFRZIQkEoHgHSTrrYCzaBWH4AEo2 AYBO1/FE41h6OCvugm/TUDNvrHA4I3RzkVH1UFGqXzosfcscXYXUTbqioW5griS3 6GJT/nIr0kDQzDSQF7/11BUCwQWAE1OX6AmcwotZJsq2+OBoapNWj3G1Dn6jcWDR htjJRPBStvUoKwhjHMJLyS46hjqvTwEuYwT50DfgM0UtAg2VbgHxtjsmL9zmrwEA fewQZPNGCItUwfwIBifUTkqJILqxphAmzMEJs5fZ7bxrk1HXSQzXzWxNpa7x7b+5 Y5IjU2MMtVHaHXyt/xq9ABk7btMCJfA9ywSV3hoKHHp0g/xdGo4zMPvF7bvnyRaQ ob2KmuwZ9oUHinJP2zaOQAeVAAFQkznS/t2T4Crm6ssipger55n4X5Xpy+OjK94/ zkrU+uzmBE8g5qQOoW5mZLFucoQv05N8aY2SehjaYgja+Au+y7RV4tkGZulrnzmu qBAqxuTJC9rtljkkAE9GQVg+kfCTHbqQRbZk42/wedCAjPyOcKV0Rqlh7BwZBaIZ kr3dGBt6hXYWDnXMLtSA =2VWF -----END PGP SIGNATURE----- --=-=-=--