unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Teemu Likonen <tlikonen@iki.fi>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 8196@debbugs.gnu.org
Subject: bug#8196: 23.1; Feature request with code: "C-x TAB" to understand tab-stop-list
Date: Sun, 14 Jul 2013 17:41:14 +0300	[thread overview]
Message-ID: <87zjtp2ohh.fsf@mithlond.arda> (raw)
In-Reply-To: <jwvbo66grpn.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Sat, 13 Jul 2013 16:02:35 -0400")

Stefan Monnier [2013-07-13 16:02:35 -04:00] wrote:

> This said, there's another good default behavior for non-prefixed C-x
> TAB which is to enter an interactive loop that lets the user move the
> block left/right with the cursor keys. I think this would be a more
> useful change.

Sounds good. I wrote a quick example command "tl-edit-indentation". It
works like "indent-rigidly" expect that when there is no prefix argument
it sets a temporary repeatable overlay keyboard with the cursor keys for
editing indentation. Plain <left> and <right> would move by 1 column and
<S-left> and <S-right> move by tab stops. I like this feature.


(defun tl-region-indentation (beg end)
  "Return the smallest indentation in range from BEG to END.
Blank lines are ignored."
  (save-excursion
    (save-match-data
      (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 tl-edit-indentation (start end arg)
  (interactive "r\nP")
  (if arg
      (indent-rigidly start end (prefix-numeric-value arg))
    (message "Edit region indentation with <left>, <right>, <S-left> \
and <S-right>.")
    (set-temporary-overlay-map

     (let ((map (make-sparse-keymap)))
       (define-key map (kbd "<left>")
         (lambda () (interactive)
           (indent-rigidly (region-beginning) (region-end) -1)))

       (define-key map (kbd "<right>")
         (lambda () (interactive)
           (indent-rigidly (region-beginning) (region-end) 1)))

       (define-key map (kbd "<S-right>")
         (lambda () (interactive)
           (let* ((beg (region-beginning))
                  (end (region-end))
                  (current (tl-region-indentation beg end))
                  (next (catch 'answer
                          (dolist (col tab-stop-list (1+ current))
                            (when (> col current)
                              (throw 'answer col))))))
             (indent-rigidly beg end (- next current)))))

       (define-key map (kbd "<S-left>")
         (lambda () (interactive)
           (let* ((beg (region-beginning))
                  (end (region-end))
                  (current (tl-region-indentation beg end))
                  (next (catch 'answer
                          (dolist (col (reverse tab-stop-list) 0)
                            (when (< col current)
                              (throw 'answer col))))))
             (indent-rigidly beg end (- next current)))))
       map)
     t)))





  reply	other threads:[~2013-07-14 14:41 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-07 18:19 bug#8196: 23.1; Feature request with code: "C-x TAB" to understand tab-stop-list Teemu Likonen
2013-07-12 17:19 ` Teemu Likonen
2013-07-12 19:11   ` Drew Adams
2013-07-12 19:18     ` Drew Adams
2013-07-12 20:05     ` Teemu Likonen
2013-07-12 21:18       ` Drew Adams
2013-07-12 22:53         ` Jambunathan K
2013-07-13  5:43           ` Teemu Likonen
2013-07-13  4:49         ` Teemu Likonen
2013-07-13  4:59           ` Drew Adams
2013-07-13 20:02 ` Stefan Monnier
2013-07-14 14:41   ` Teemu Likonen [this message]
2013-10-08  6:18     ` Stefan Monnier
2013-10-08 15:12       ` Drew Adams
2013-10-08 15:34         ` Teemu Likonen
2013-10-08 16:21           ` Drew Adams

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=87zjtp2ohh.fsf@mithlond.arda \
    --to=tlikonen@iki.fi \
    --cc=8196@debbugs.gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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).