all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: michael.cadilhac@lrde.org (Michaël Cadilhac)
Cc: emacs-devel@gnu.org
Subject: Re: [Proposal] M-x tabify to indent only when needed.
Date: Tue, 25 Jul 2006 13:38:24 +0200	[thread overview]
Message-ID: <877j213oen.fsf@lrde.org> (raw)
In-Reply-To: <E1G58Jn-0005k5-0l@fencepost.gnu.org> (Richard Stallman's message of "Mon, 24 Jul 2006 17:50:27 -0400")


[-- Attachment #1.1.1: Type: text/plain, Size: 735 bytes --]

Richard Stallman <rms@gnu.org> writes:

>     ! 	  (unless (save-match-data
>     ! 		    (save-excursion
>     ! 		      (goto-char (match-beginning 0))
>     ! 		      (string-match
>     ! 		       (format "^\t* \\{0,%d\\}$"
>     ! 			       (- tab-width (1+ (mod (current-column) tab-width))))
>     ! 		       (match-string 0))))
>
> That would be very slow.  Please do it without using regexps,
> perhaps using skip-chars-forward.

I can come up with the following regexp-free, search-free patch that
makes the job, and that uses Stefan's good proposal of using " [ \t]+"
as `tabify-regexp'.

However, the code now supposes that if a TAB appears in the match,
a space must have preceded it.  I specified that in the docstring.


[-- Attachment #1.1.2: tabify.patch --]
[-- Type: text/x-patch, Size: 2745 bytes --]

Index: lisp/tabify.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/tabify.el,v
retrieving revision 1.19
diff -c -r1.19 tabify.el
*** lisp/tabify.el	6 Feb 2006 14:33:35 -0000	1.19
--- lisp/tabify.el	25 Jul 2006 10:30:09 -0000
***************
*** 50,59 ****
  	  (delete-region tab-beg (point))
  	  (indent-to column))))))
  
! (defvar tabify-regexp "[ \t][ \t]+"
    "Regexp matching whitespace that tabify should consider.
! Usually this will be \"[ \\t][ \\t]+\" to match two or more spaces or tabs.
! \"^[ \\t]+\" is also useful, for tabifying only initial whitespace.")
  
  ;;;###autoload
  (defun tabify (start end)
--- 50,60 ----
  	  (delete-region tab-beg (point))
  	  (indent-to column))))))
  
! (defvar tabify-regexp " [ \t]+"
    "Regexp matching whitespace that tabify should consider.
! Usually this will be \" [ \\t]+\" to match two or more spaces or tabs.
! \"^\\\\( \\t*\\\\)+\" is also useful, for tabifying only initial whitespace.
! Note that if a `\\t' is matched, a space must have been matched before.")
  
  ;;;###autoload
  (defun tabify (start end)
***************
*** 75,82 ****
        (while (re-search-forward tabify-regexp nil t)
  	(let ((column (current-column))
  	      (indent-tabs-mode t))
! 	  (delete-region (match-beginning 0) (point))
! 	  (indent-to column))))))
  
  (provide 'tabify)
  
--- 76,94 ----
        (while (re-search-forward tabify-regexp nil t)
  	(let ((column (current-column))
  	      (indent-tabs-mode t))
! 	  (unless (save-excursion
! 		    (if (not (= (skip-chars-backward " " (match-beginning 0))
! 				(- (match-beginning 0) (match-end 0))))
! 			;; There is a TAB after a space: (match-string 0) is
! 			;; not full of spaces.
! 			nil
! 		      ;; See if there's room for a TAB.
! 		      ;; We already are at (match-beginning 0).
! 		      (< (+ (mod (current-column) tab-width)
! 			    (- column (current-column)))
! 			 tab-width)))
! 	    (delete-region (match-beginning 0) (point))
! 	    (indent-to column)))))))
  
  (provide 'tabify)
  
Index: lisp/ChangeLog
===================================================================
RCS file: /sources/emacs/emacs/lisp/ChangeLog,v
retrieving revision 1.9820
diff -c -r1.9820 ChangeLog
*** lisp/ChangeLog	17 Jul 2006 04:07:48 -0000	1.9820
--- lisp/ChangeLog	25 Jul 2006 10:30:10 -0000
***************
*** 1,3 ****
--- 1,7 ----
+ 2006-07-24  Michaël Cadilhac  <michael.cadilhac@lrde.org>
+ 
+ 	* tabify.el (tabify): Check if not already tabified before indenting.
+ 
  2006-07-17  Chong Yidong  <cyd@stupidchicken.com>
  
  	* progmodes/compile.el (compilation-mode-font-lock-keywords):

[-- Attachment #1.1.3: Type: text/plain, Size: 404 bytes --]


The understanding is slightly improved :-) I can't make it clearer, in
fact.

-- 
 |      Michaël `Micha' Cadilhac   |  Isn't vi that text editor with        |
 |         Epita/LRDE Promo 2007   |   two modes... One that beeps and      |
 | http://www.lrde.org/~cadilh_m   |     one that corrupts your file?       |
 `--  -   JID: micha@amessage.be --'           -- Dan Jacobson         -  --'

[-- Attachment #1.2: Type: application/pgp-signature, Size: 188 bytes --]

[-- Attachment #2: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

  reply	other threads:[~2006-07-25 11:38 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-24 17:30 [Proposal] M-x tabify to indent only when needed Michaël Cadilhac
2006-07-24 20:40 ` Michaël Cadilhac
2006-07-24 21:30   ` Stefan Monnier
2006-07-25  3:09     ` Richard Stallman
2006-07-25 13:55       ` Stefan Monnier
2006-07-25 14:09         ` Michaël Cadilhac
2006-07-25 15:07           ` Stefan Monnier
2006-07-25 15:28             ` Michaël Cadilhac
2006-07-25 16:21               ` Stefan Monnier
2006-07-25 17:09                 ` Michaël Cadilhac
2006-07-24 21:50 ` Richard Stallman
2006-07-25 11:38   ` Michaël Cadilhac [this message]
2006-07-25 22:15     ` Richard Stallman
2006-07-26 11:29       ` Michaël Cadilhac
2006-07-26 11:32         ` Michaël Cadilhac

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877j213oen.fsf@lrde.org \
    --to=michael.cadilhac@lrde.org \
    --cc=emacs-devel@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.
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.