From: pjb@informatimago.com (Pascal J. Bourguignon)
To: help-gnu-emacs@gnu.org
Subject: Re: Creating a Tab binding to use within comments and other text ??
Date: Sat, 19 Sep 2009 21:15:43 +0200 [thread overview]
Message-ID: <877hvueof4.fsf@galatea.local> (raw)
In-Reply-To: mailman.7060.1253380461.2239.help-gnu-emacs@gnu.org
William Case <billlinux@rogers.com> writes:
> Hi;
>
> I started out this morning to create a key binding for a different TAB
> key but nothing is working right.
>
> I want to keep TAB, M-i and M-j just as they are. I use them regularly.
>
> But for text writing, particularly within comments, I want a 'text-tab'
> that I can use to lineup lists and bullet points, sub topics etc. I
> don't want this 'text-tab' to interfere with the operation of the above.
>
> It would be nice if I had a way to set tab stops for this 'text-tab'
> that is independent of the main tab-stop bar.
>
> So far I have being trying to bind something to s-i (s-<TAB> would be
> useful as well) but almost any key combination would do.
>
> Nothing on the Wiki jumped out at me. All the possibilities there seem
> to be for altering the main TAB functions.
>
> Any suggestions?
You may bind your own command, that would first check whether it's
inside a comment, and if not, it would call the original command.
However, each mode may override the key bindings, such as that of TAB.
If you want to be able to override any tab command, the we would have
to hook to a lower level, that is, you would have to patch the C
function call-interactively.
An alternative would be to modify the mode where you want to have this
behavior (possibly thru a mode specific hook).
Here is a more ad-hoc way to do it:
(defvar *original-tab-command* nil)
(make-local-variable '*original-tab-command*)
(defun install-my-tab ()
(interactive)
(unless (eql (key-binding (kbd "TAB")) 'my-tab)
(setf *original-tab-command* (key-binding (kbd "TAB")))
(local-set-key (kbd "TAB") 'my-tab)))
(defun my-tab ()
(interactive)
(if (save-excursion (comment-beginning))
;; inside a comment
(progn
;; do whatever you want. For example, insert four spaces:
(insert " "))
(call-interactively *original-tab-command*)))
So in a buffer where you want to override the current TAB command in
comments, you could run M-x install-my-tab RET.
--
__Pascal Bourguignon__
next parent reply other threads:[~2009-09-19 19:15 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.7060.1253380461.2239.help-gnu-emacs@gnu.org>
2009-09-19 19:15 ` Pascal J. Bourguignon [this message]
2009-09-19 17:12 Creating a Tab binding to use within comments and other text ?? William Case
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=877hvueof4.fsf@galatea.local \
--to=pjb@informatimago.com \
--cc=help-gnu-emacs@gnu.org \
/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.
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).