all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Tabs (yikes)
@ 2003-03-18 16:24 Tony Vitonis
  2003-03-18 18:40 ` Karl Pflästerer
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Tony Vitonis @ 2003-03-18 16:24 UTC (permalink / raw)


Hi.  I'm a newbie having a tough time getting tabs to work the way I
want in Emacs.  (From the searches I've done, I'm not alone in this
regard. :))

My problem is this: In text mode, I want the Tab key to move to the
next default-tab-width stop, no matter what the context.  I've been
able to do it with these options:

   (define-key text-mode-map [tab] 'tab-to-tab-stop)
   (setq tab-stop-list '(3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48
51 54 57 60 63 66 69 72 75 78))

But I can *not* seem to find a way to make it happen using my
default-tab-width, which I've specified this way:

   (setq default-tab-width 3)

Is there any way to make this happen without typing in the long dreary
list of tab stops?  Thanks very much.

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

* Re: Tabs (yikes)
  2003-03-18 16:24 Tabs (yikes) Tony Vitonis
@ 2003-03-18 18:40 ` Karl Pflästerer
  2003-03-18 18:44 ` Benjamin Rutt
       [not found] ` <5lu1e0wl2u.fsf@rum.cs.yale.edu>
  2 siblings, 0 replies; 4+ messages in thread
From: Karl Pflästerer @ 2003-03-18 18:40 UTC (permalink / raw)


On 18 Mar 2003, Tony Vitonis <- vitonis@comcast.deletethis.net wrote:

>(define-key text-mode-map [tab] 'tab-to-tab-stop)
>(setq tab-stop-list '(3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48
>51 54 57 60 63 66 69 72 75 78))

>But I can *not* seem to find a way to make it happen using my
>default-tab-width, which I've specified this way:

>Is there any way to make this happen without typing in the long dreary
>list of tab stops?  Thanks very much.

You could write a function which computes the list for you. Here are two
solutions. The first uses recursion, the second one uses iteration but
if you have Gnu Emacs you would have to write `(require 'cl)' to be able
to use it.

(defun return-tabslist (start end &optional step)
  (if (< end start)
    nil
    (cons start
	  (return-tabslist (+ start (or step default-tab-width)) end))))

(defun return-tabslist (start end &optional step)
  (loop for x from start to end by (or step default-tab-width)
	collect x))

bye
   KP

-- 
"But it has nothing to do with what a _value_ is.  This has to do with
whether you pass whatever-a-value-is or wherever-whatever-is-a-value-is
whenever you pass an argument to a function.  (Call it the Shakira
theory. :)"       [Erik Naggum in cll über call-by-value und call-by-reference]

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

* Re: Tabs (yikes)
  2003-03-18 16:24 Tabs (yikes) Tony Vitonis
  2003-03-18 18:40 ` Karl Pflästerer
@ 2003-03-18 18:44 ` Benjamin Rutt
       [not found] ` <5lu1e0wl2u.fsf@rum.cs.yale.edu>
  2 siblings, 0 replies; 4+ messages in thread
From: Benjamin Rutt @ 2003-03-18 18:44 UTC (permalink / raw)


"Tony Vitonis" <vitonis@comcast.deletethis.net> writes:

> My problem is this: In text mode, I want the Tab key to move to the
> next default-tab-width stop, no matter what the context.  I've been
> able to do it with these options:
>
>    (define-key text-mode-map [tab] 'tab-to-tab-stop)
>    (setq tab-stop-list '(3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48
> 51 54 57 60 63 66 69 72 75 78))
>
> But I can *not* seem to find a way to make it happen using my
> default-tab-width, which I've specified this way:

tab-width (which is derived from default-tab-width if unset) is used
to control the display of tabs in buffers, not to control what happens
when you press the TAB key.  Your solution of setting the
tab-stop-list is basically the right idea.  I use the following code
in several places to build up the list appropriately in various major
modes:

(defun my-build-tab-stop-list (width)
  (interactive "nEnter desired width: ")
  (let ((num-tab-stops (/ 80 width))
	(counter 1)
	(ls nil))
    (while (<= counter num-tab-stops)
      (setq ls (cons (* width counter) ls))
      (setq counter (1+ counter)))
    (setq tab-stop-list (nreverse ls))))

Then, in your case, you can do a (my-build-tab-stop-list 3), which is a
little cleaner.

Note that you'll also want (setq tab-width 3) in text-mode so that
your displayed tabs look correct on files you've created with the
above settings.
-- 
Benjamin

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

* Re: Tabs (yikes)
       [not found] ` <5lu1e0wl2u.fsf@rum.cs.yale.edu>
@ 2003-03-18 19:28   ` Stefan Monnier
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2003-03-18 19:28 UTC (permalink / raw)
  Cc: emacs-devel

The following message is a courtesy copy of an article
that has been posted to gnu.emacs.help as well.

> Actually, once you pass the last tab-stop in `tab-stop-list',
> `tab-to-tab-stop' just inserts a TAB character, which does have

I need sleep: it doesn't insert a TAB but a space.
It sounds wrong.  How about the patch below ?


        Stefan


--- indent.el	14 Mar 2003 23:11:20 -0000	1.54
+++ indent.el	18 Mar 2003 19:26:49 -0000
@@ -498,14 +586,19 @@
   (interactive)
   (and abbrev-mode (= (char-syntax (preceding-char)) ?w)
        (expand-abbrev))
-  (let ((tabs tab-stop-list))
-    (while (and tabs (>= (current-column) (car tabs)))
+  (let ((tabs tab-stop-list)
+	(col (current-column)))
+    (while (and tabs (>= col (car tabs)))
       (setq tabs (cdr tabs)))
-    (if tabs
-	(let ((opoint (point)))
 	  (delete-horizontal-space t)
-	  (indent-to (car tabs)))
-      (insert ?\ ))))
+    (indent-to
+     (if tabs (car tabs)
+       ;; We passed the end of tab-stop-list: guess a continuation.
+       (let* ((last (last tab-stop-list 2))
+	      (step (if (cdr last) (- (cadr last) (car last)) tab-width)))
+	 (setq last (or (cadr last) (car last) 0))
+	 ;; Repeat the last tab's length.
+	 (+ last (* step (1+ (/ (- col last) step)))))))))
 
 (defun move-to-tab-stop ()
   "Move point to next defined tab-stop column.

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

end of thread, other threads:[~2003-03-18 19:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-03-18 16:24 Tabs (yikes) Tony Vitonis
2003-03-18 18:40 ` Karl Pflästerer
2003-03-18 18:44 ` Benjamin Rutt
     [not found] ` <5lu1e0wl2u.fsf@rum.cs.yale.edu>
2003-03-18 19:28   ` Stefan Monnier

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.