[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Indenting paragraphs manually

From: Teemu Likonen
Subject: Re: Indenting paragraphs manually
Date: Mon, 07 Mar 2011 16:52:17 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2.94 (gnu/linux)

* 2011-03-07 22:38 (+0800), Le Wang wrote:

> Teemu, one bug in the code is that you need to call (require 'repeat)
> at the beginning, otherwise when it gets autoloaded later
> `repeat-message-function' doesn't get initialized properly because of
> the "(let ..." binding.

Thanks. I have made some other adjustments too, so here's a new version:

(defun tl-region-indentation (beg end)
  "Return the smallest indentation in range from BEG to END.
Blank lines are ignored."
    (let ((beg (progn (goto-char beg) (line-beginning-position)))
      (goto-char beg)
      (while (re-search-forward "^\\s-*[[:print:]]" end t)
        (setq indent (min (or indent (current-indentation))

(defun tl-indent-region-engine (beg end arg)
  "Back-end function for `tl-indent-region'."
  (interactive "r\nP")
  (let* ((beg (save-excursion (goto-char beg) (line-beginning-position)))
         (current (tl-region-indentation beg end))
         (indent (cond ((not arg)
                        (- (catch 'answer
                             (dolist (col tab-stop-list (1+ current))
                               (when (> col current)
                                 (throw 'answer col))))
                       ((eq arg '-)
                        (- (catch 'answer
                             (dolist (col (reverse tab-stop-list) 0)
                               (when (< col current)
                                 (throw 'answer col))))
                       (t (prefix-numeric-value arg)))))
    (indent-rigidly beg end indent)))

(defun tl-indent-region (beg end arg)
  "Indent region to a tab stop column or to a 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'. If ARG is negative indent the region to the
previous tab stop column. If ARG is a positive or negative
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

  (interactive "r\nP")
  (require 'repeat)
  (let ((repeat-message-function #'ignore))
    (setq last-repeatable-command #'tl-indent-region-engine)
    (repeat nil)))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]