From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: michael.cadilhac@lrde.org (=?iso-8859-1?Q?Micha=EBl?= Cadilhac) Newsgroups: gmane.emacs.devel Subject: Re: [Proposal] M-x tabify to indent only when needed. Date: Tue, 25 Jul 2006 13:38:24 +0200 Organization: Epita/LRDE Message-ID: <877j213oen.fsf@lrde.org> References: <8764hm7vwo.fsf@lrde.org> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0634881755==" X-Trace: sea.gmane.org 1153823492 22183 80.91.229.2 (25 Jul 2006 10:31:32 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 25 Jul 2006 10:31:32 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jul 25 12:31:28 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1G5KCF-00016g-03 for ged-emacs-devel@m.gmane.org; Tue, 25 Jul 2006 12:31:27 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1G5KCE-0005zB-Eh for ged-emacs-devel@m.gmane.org; Tue, 25 Jul 2006 06:31:26 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1G5KC0-0005yZ-01 for emacs-devel@gnu.org; Tue, 25 Jul 2006 06:31:12 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1G5KBy-0005y6-IZ for emacs-devel@gnu.org; Tue, 25 Jul 2006 06:31:11 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1G5KBy-0005y1-F0 for emacs-devel@gnu.org; Tue, 25 Jul 2006 06:31:10 -0400 Original-Received: from [62.39.139.2] (helo=kualalumpur.lrde.epita.fr) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1G5KDC-0008I8-LO; Tue, 25 Jul 2006 06:32:27 -0400 Original-Received: from mahaena.lrde.epita.fr ([192.168.101.66] helo=mahaena.lrde) by kualalumpur.lrde.epita.fr with esmtp (Exim 4.50) id 1G5KBt-0006VH-5d; Tue, 25 Jul 2006 12:31:05 +0200 Original-To: rms@gnu.org Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAElBMVEVWPh+Tai+5r5YKBAEU CQQzGAtiq7gjAAACR0lEQVQ4jW2UzW7lIAyFzVW8BzTZX5DmCZLuU2H2pMXv/ypzbK7aSh2kRCRf /HNsE0q7Sg+RQ7JFKaqtrRNAl5AIIKe6D5DBqgbmUAe5hBI1wIRFAHjeM0RKtZi7XVVEpb0BSNfA IddChChT5DildSLWOWhY5IEItMnncZgFcUAc/5jjwCMsDosRNdfKPDTFEdVBW8C+RebDb4N5Orio RhM1+11IJyx0ng2+LryFHBMPDQDYHrY6IfGuU3ouiXTQNE8LIJDKOWpNxERTFrggQwRPd7USUsTW fJ0XbR3bdj5KgBYy4SACpxDeUYEUAzLmtJ1iIrD2gczPq8Qomjhsh/RjGIgKIO8p7NITjwlx7WID nsnQe5NeuTvoBpi8LX6vLLOh5icjOHqBypgnuSp7M+RE1agbQKHQr5E2z1WObhYW4gMqeGQL7joM jCf2DxSk5ApADSYHfFF4igNfJZL1z0GKP0FN02s4XiDXr7V5P94W6I9v8MfBOQDmfwAaVYt+x8Da v4DJvX8BAdin3Knm5yMZYAO4ABDkDniZLLfi4P40gP1F0TPGZOu0CGwA1lcowxwlGy6A9705mD0V jHCxwVZT/hYdRJVUGZNlx6l7ScQBTluof6Wj6bsPYlvpwoTvXFD9gHPn2TZPF3ntI2ecxVrW5MrV XiCie5EeNa7BlWu/HNSkprDUva163PHxAv5jyGV7gVzyAghSKOTnat85UIYFICXbD2NV9rRiv0BS tKQsg6OHH4A15F1WW+UHKHHa32h6aPnAm3/pUcWp+WYnTQAAAABJRU5ErkJggg== In-Reply-To: (Richard Stallman's message of "Mon, 24 Jul 2006 17:50:27 -0400") User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.50 (gnu/linux) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:57601 Archived-At: --===============0634881755== Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Richard Stallman 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. --=-=-= Content-Type: text/x-patch; charset=iso-8859-1 Content-Disposition: inline; filename=tabify.patch Content-Transfer-Encoding: quoted-printable Index: lisp/tabify.el =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 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 =2D-- lisp/tabify.el 25 Jul 2006 10:30:09 -0000 *************** *** 50,59 **** (delete-region tab-beg (point)) (indent-to column)))))) =20=20 ! (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 tab= s. ! \"^[ \\t]+\" is also useful, for tabifying only initial whitespace.") =20=20 ;;;###autoload (defun tabify (start end) =2D-- 50,60 ---- (delete-region tab-beg (point)) (indent-to column)))))) =20=20 ! (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 whitespa= ce. ! Note that if a `\\t' is matched, a space must have been matched before.") =20=20 ;;;###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)))))) =20=20 (provide 'tabify) =20=20 =2D-- 76,94 ---- (while (re-search-forward tabify-regexp nil t) (let ((column (current-column)) (indent-tabs-mode t)) ! (unless (save-excursion ! (if (not (=3D (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))))))) =20=20 (provide 'tabify) =20=20 Index: lisp/ChangeLog =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 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 =2D-- lisp/ChangeLog 25 Jul 2006 10:30:10 -0000 *************** *** 1,3 **** =2D-- 1,7 ---- + 2006-07-24 Micha=EBl Cadilhac +=20 + * tabify.el (tabify): Check if not already tabified before indenting. +=20 2006-07-17 Chong Yidong =20=20 * progmodes/compile.el (compilation-mode-font-lock-keywords): --=-=-= Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable The understanding is slightly improved :-) I can't make it clearer, in fact. =2D-=20 | Micha=EBl `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 - -= -' --=-=-=-- --==-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (GNU/Linux) iD8DBQFExgKzZYNf4qobZ7kRAinCAKCOpE5PUL0RppAahyzzc/RdPv1DXwCfUp8g ptsucpjtLM5Xv+uzk4lb0Is= =qC2J -----END PGP SIGNATURE----- --==-=-=-- --===============0634881755== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel --===============0634881755==--