From: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: [Proposal] M-x tabify to indent only when needed.
Date: Mon, 24 Jul 2006 17:30:42 -0400 [thread overview]
Message-ID: <jwv3bcqpvfe.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87irlm68k0.fsf@lrde.org> (Michaël Cadilhac's message of "Mon, 24 Jul 2006 22:40:15 +0200")
> (while (re-search-forward tabify-regexp nil t)
> (let ((column (current-column))
> (indent-tabs-mode t))
> ! ;; Whether already tabified.
> ! (unless (save-match-data
> ! (save-excursion
> ! (skip-chars-backward " ")
> ! (string-match
> ! (format "^\t* \\{0,%d\\}$"
> ! (- tab-width (1+ (mod (current-column) tab-width))))
> ! (match-string 0))))
> ! (delete-region (match-beginning 0) (point))
> ! (indent-to column)))))))
I'm not convinced it's correct.
I think we should only accept such a patch if the correctness is clear
(either because the code's correctnes is inherently obvious, or because it
is sufficiently commented to explain why it's correct).
How 'bout the 100% untested patch below?
Stefan
--- orig/lisp/tabify.el
+++ mod/lisp/tabify.el
@@ -50,9 +50,9 @@
(delete-region tab-beg (point))
(indent-to column))))))
-(defvar tabify-regexp "[ \t][ \t]+"
+(defvar tabify-regexp " [ \t]+"
"Regexp matching whitespace that tabify should consider.
-Usually this will be \"[ \\t][ \\t]+\" to match two or more spaces or tabs.
+Usually this will be \" [ \\t]+\" to match two or more spaces or tabs.
\"^[ \\t]+\" is also useful, for tabifying only initial whitespace.")
;;;###autoload
@@ -73,12 +73,20 @@
(narrow-to-region (point) end)
(goto-char start)
(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))))))
+ ;; The region between (match-beginning 0) and (match-end 0) is just
+ ;; spacing which we want to adjust to use TABs where possible.
+ (let ((end-col (current-column))
+ (beg-col (save-excursion (goto-char (match-beginning 0))
+ (current-column))))
+ (if (= (/ end-col tab-width) (/ beg-col tab-width))
+ ;; The spacing does not straddle a TAB boundary, so we won't
+ ;; be able to use a TAB here anyway: there's nothing to do.
+ nil
+ (let ((indent-tabs-mode t))
+ (delete-region (match-beginning 0) (point))
+ (indent-to end-col))))))))
(provide 'tabify)
-;;; arch-tag: c83893b1-e0cc-4e57-8a09-73fd03466416
+;; arch-tag: c83893b1-e0cc-4e57-8a09-73fd03466416
;;; tabify.el ends here
next prev parent reply other threads:[~2006-07-24 21:30 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 [this message]
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
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwv3bcqpvfe.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).