From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: pjb@informatimago.com (Pascal J. Bourguignon) Newsgroups: gmane.emacs.help Subject: Re: Creating a Tab binding to use within comments and other text ?? Date: Sat, 19 Sep 2009 21:15:43 +0200 Organization: Informatimago Message-ID: <877hvueof4.fsf@galatea.local> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1253389246 5914 80.91.229.12 (19 Sep 2009 19:40:46 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 19 Sep 2009 19:40:46 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Sep 19 21:40:40 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Mp5nS-00033R-4I for geh-help-gnu-emacs@m.gmane.org; Sat, 19 Sep 2009 21:40:38 +0200 Original-Received: from localhost ([127.0.0.1]:48109 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mp5nR-0007tN-Ho for geh-help-gnu-emacs@m.gmane.org; Sat, 19 Sep 2009 15:40:37 -0400 Original-Path: news.stanford.edu!usenet.stanford.edu!news.glorb.com!news2.glorb.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 66 Original-X-Trace: individual.net BRH61vSj2vDSGQBaxy1rjwsutYJ0ifYiOGKbcwIuqxlr8ru9jo Cancel-Lock: sha1:ZGRlYzhlMTVkYjg1NjdmOTRhMzg1YjM1YjE3OWMwZGUyY2NiMmE1OA== sha1:vNQjfQReEakFfLkX6PUhlvyba1U= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en X-Disabled: X-No-Archive: no User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.3 (darwin) Original-Xref: news.stanford.edu gnu.emacs.help:173184 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:68307 Archived-At: William Case 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- 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__