help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Use tab key to indent both region AND line?


From: Lennart Borgman (gmail)
Subject: Re: Use tab key to indent both region AND line?
Date: Sat, 21 Apr 2007 00:41:41 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.10) Gecko/20070221 Thunderbird/1.5.0.10 Mnenhy/0.7.5.666

Lennart Borgman (gmail) wrote:
weber wrote:

(defun indent-line-or-region ()
  "indent line or region"
  (interactive)
  (if mark-active   ;; there is a region selected
      (indent-region)
      (indent-according-to-mode))) ;; indent line

Just bind it to tab.

Hope i could help you,
-weber


And here is something that can be used:

;; From an idea by weber <hugows@gmail.com>
(defun indent-line-or-region ()
  "indent line or region"
  (interactive)
  (if mark-active ;; there is a region selected
      (indent-region (region-beginning) (region-end))
    (indent-according-to-mode))) ;; indent line

(define-minor-mode indent-line-mode
  "Use TAB to indent line and region."
  :global t
  :keymap '(([tab] . indent-line-or-region)))
(when indent-line-mode (indent-line-mode 1))


And here is something that can actually be used ;-)

After using the above for some minutes I realized that you do not want to indent in all buffers. Here is a heuristic solution to that problem:

;; From an idea by weber <hugows@gmail.com>
(defun indent-line-or-region ()
  "indent line or region"
  (interactive)
  ;; Do a wild guess if we should indent or not ...
  (let* ((indent-line-mode)
         (t-bound (key-binding [?\t]))
         (do-indent)
        )
    (if (not
         (save-match-data
           (string-match "indent" (symbol-name t-bound))))
        (call-interactively t-bound t)
      (if mark-active ;; there is a region selected
          (indent-region (region-beginning) (region-end))
        (indent-according-to-mode))))) ;; indent line

(define-minor-mode indent-line-mode
  "Use TAB to indent line and region."
  :global t
  :keymap '(([?\t] . indent-line-or-region)))
(when indent-line-mode (indent-line-mode 1))




reply via email to

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