all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Creating a Tab binding to use within comments and other text ??
@ 2009-09-19 17:12 William Case
  0 siblings, 0 replies; 2+ messages in thread
From: William Case @ 2009-09-19 17:12 UTC (permalink / raw)
  To: Emacs Help List

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?

-- 
Regards Bill
Fedora 11, Gnome 2.26.3
Evo.2.26.3, Emacs 23.1.1





^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Creating a Tab binding to use within comments and other text ??
       [not found] <mailman.7060.1253380461.2239.help-gnu-emacs@gnu.org>
@ 2009-09-19 19:15 ` Pascal J. Bourguignon
  0 siblings, 0 replies; 2+ messages in thread
From: Pascal J. Bourguignon @ 2009-09-19 19:15 UTC (permalink / raw)
  To: help-gnu-emacs

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__


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-09-19 19:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-19 17:12 Creating a Tab binding to use within comments and other text ?? William Case
     [not found] <mailman.7060.1253380461.2239.help-gnu-emacs@gnu.org>
2009-09-19 19:15 ` Pascal J. Bourguignon

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.