From: "Lennart Borgman (gmail)" <lennart.borgman@gmail.com>
Cc: help-gnu-emacs@gnu.org, weber <hugows@gmail.com>
Subject: Re: Use tab key to indent both region AND line?
Date: Sat, 21 Apr 2007 00:41:41 +0200 [thread overview]
Message-ID: <462941A5.6070105@gmail.com> (raw)
In-Reply-To: <4628F55B.2060005@gmail.com>
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))
next prev parent reply other threads:[~2007-04-20 22:41 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-20 12:10 Use tab key to indent both region AND line? mopi
2007-04-20 12:45 ` Denis Bueno
2007-04-20 13:58 ` Livin Stephen Sharma
[not found] ` <mailman.2307.1177077814.7795.help-gnu-emacs@gnu.org>
2007-04-20 16:01 ` weber
2007-04-20 17:16 ` Lennart Borgman (gmail)
2007-04-20 22:41 ` Lennart Borgman (gmail) [this message]
[not found] ` <mailman.2326.1177089678.7795.help-gnu-emacs@gnu.org>
2007-04-20 17:54 ` mopi
2007-04-20 19:07 ` mopi
2007-04-20 22:12 ` weber
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=462941A5.6070105@gmail.com \
--to=lennart.borgman@gmail.com \
--cc=help-gnu-emacs@gnu.org \
--cc=hugows@gmail.com \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.