[net.emacs] Tabbing in C Mode

martillo@mit-athena.UUCP (Joaquim Martillo) (07/08/85)

In C-mode tabs indent the current line to the proper position  according
to  level.   If  you  want  to get tabs anywhere else on the line, it is
hard.  Here is one possible function to do this.

(defun insert-tab (&optional arg)
  (interactive "p")			; So that function can be called
					; interactively with prefix 
  					; argument.
  (let ((temp-tab-stop-list tab-stop-list)	; tab-stop-list is a 
						; global containing all
						; tab-stops
	(nearest-tab-stop (car tab-stop-list)))
    (if (null arg)
	(setq arg 1))
    (while (> arg 0)
      (if (null temp-tab-stop-list)
	  (insert "\t")
	(progn
	  (set-mark (dot))		; The progn is to handle those
					; who are into arbitrary tabbing
	  (while (<=  nearest-tab-stop (current-column))
	    (setq temp-tab-stop-list (cdr temp-tab-stop-list))
	    (setq nearest-tab-stop (car temp-tab-stop-list)))
	  (while (< (current-column) nearest-tab-stop)
	    (insert " "))
	  (tabify (mark) (dot))))	; Convert spaces to tabs
      (setq arg (1- arg)))))

(define-key esc-map "\^i" 'insert-tab)	; bind function to M-C-i or 
					; <esc> C-i

barmar@mit-eddie.UUCP (Barry Margolin) (07/09/85)

In article <280@mit-athena.UUCP> martillo@mit-athena.UUCP (Joaquim Martillo) writes:
>In C-mode tabs indent the current line to the proper position  according
>to  level.   If  you  want  to get tabs anywhere else on the line, it is
>hard.  Here is one possible function to do this.
>
>(defun insert-tab (&optional arg)
>...
>(define-key esc-map "\^i" 'insert-tab)	; bind function to M-C-i or 
>					; <esc> C-i


What's wrong with C-q TAB (besides flow control problems, which I know
are not a problem at Athena)?  C-q is quoted-insert, which inserts the
character typed, rather than executing it.  This is true in almost all
the versions of Emacs I have used, and I just verified it in GNU Emacs.
-- 
    Barry Margolin
    ARPA: barmar@MIT-Multics
    UUCP: ..!genrad!mit-eddie!barmar

martillo@mit-athena.UUCP (Joaquim Martillo) (07/09/85)

The problem is for those who are creative in their tabbing.  If you have
adjusted  your  tabstops  C-Q  C-I can lead to problems.  Also while the
function tabifies, a person who really wants spaces instead of tabs  can
easily  remove  the  tabify  command.   Last  C-Q C-I is not amenable to
prefix argument. If you wish to enter 4 tabs you have use C-U 4 C-Q  C-I
C-I C-I C-I.

alan@cucca.UUCP (Alan Crosswell) (07/09/85)

In article <280@mit-athena.UUCP> martillo@mit-athena.UUCP (Joaquim Martillo) writes:
>In C-mode tabs indent the current line to the proper position  according
>to  level.   If  you  want  to get tabs anywhere else on the line, it is
>hard.  Here is one possible function to do this.

Can't you just quote the tab character (i.e. C-Q C-I)?

martillo@mit-athena.UUCP (Joaquim Martillo) (07/10/85)

C-Q C-I will not work properly if the tab-stops have been  edited.   Try
the  function edit-tab-stops to see the problem. Put the tabs at 4 space
intervals rather than 8 space intervals.  Then try C-Q C-I.   An  actual
tab  will  be  inserted which will then be on output expanded to up to 8
spaces. The function contained an error.  It should have been:

(defun insert-tab (&optional arg)
       (interactive "p")
       (let ((temp-tab-stop-list tab-stop-list)
	     (nearest-tab-stop (car tab-stop-list)))
	    (if (null arg)
		(setq arg 1))
	    (set-mark (dot))
	    (while (> arg 0)
		   (if (null temp-tab-stop-list)
		       (insert "\t")
		       (progn
			(while (<=  nearest-tab-stop (current-column))
			       (setq temp-tab-stop-list
				     (cdr temp-tab-stop-list))
			       (setq nearest-tab-stop 
				     (car temp-tab-stop-list)))
			(while (< (current-column) nearest-tab-stop)
			       (insert " "))
			(tabify (mark) (dot))))
		   (setq arg (1- arg)))))

(define-key esc-map "\^i" 'insert-tab)

The set-mark was in the wrong place.

rusty@sdcarl.UUCP (rusty c. wright) (07/11/85)

In article <4628@mit-eddie.UUCP> barmar@mit-eddie.UUCP (Barry Margolin) writes:
>What's wrong with C-q TAB (besides flow control problems, which I know
>are not a problem at Athena)?  C-q is quoted-insert, which inserts the
>character typed, rather than executing it.  This is true in almost all
>the versions of Emacs I have used, and I just verified it in GNU Emacs.

That's STUPID!  Why in the world should anybody have to type ctl-q in
front of a tab everywhere else when they don't have to when they're
at the beginning of a line.  It's a COMPLETELY MORONIC concept.
-- 
	rusty c. wright
	{ucbvax,ihnp4,akgua,hplabs,sdcsvax}!sdcarl!rusty

barmar@mit-eddie.UUCP (Barry Margolin) (07/11/85)

In article <281@mit-athena.UUCP> martillo@mit-athena.UUCP (Joaquim Martillo) writes:
>   Last  C-Q C-I is not amenable to
>prefix argument. If you wish to enter 4 tabs you have use C-U 4 C-Q  C-I
>C-I C-I C-I.

Your other arguments against C-q C-i were valid.  However, this is
wrong.  I just tried both "ESC 4 C-q C-i" and "C-u C-q C-i" and four
tabs were inserted in each case.
-- 
    Barry Margolin
    ARPA: barmar@MIT-Multics
    UUCP: ..!genrad!mit-eddie!barmar