Emacs integration: hg-strip, hg-chomp improvements

Dan Christensen jdc at uwo.ca
Wed Aug 31 13:32:28 CDT 2005


hg-strip was removing leading whitespace on each line, not just
at the beginning and end of the str.  This messed up some of my
nicely formatted commit messages.  ^ and $ match the beginning
and end of lines, while \` and \' match the beginning and the
end of the string.  Note that the new regexp is designed to also
not strip leading spaces on the first line and trailing spaces
on the last line, although mercurial itself seems to strip
the leading spaces on the first line.

I'm not sure about the hg-chomp portion of the patch; I made
the guess that a similar change would be useful, but didn't
investigate.

By the way, Bryan, do you want followups mailed to you as well
as the mailing list?  You don't supply a mail-followup-to header, so
this is what my client does by default.  (I prefer to not be mailed
directly.)

Dan

# HG changeset patch
# User jdc at uwo.ca
# Node ID 3b37711b16e30b03742bdc3c46038d4b1f58a91d
# Parent  9d9f4973c76ad99a1e977eecc652559e12f53aef
Adjust hg-strip and hg-chomp regexps.

diff -r 9d9f4973c76a -r 3b37711b16e3 contrib/mercurial.el
--- a/contrib/mercurial.el	Wed Aug 31 07:01:41 2005
+++ b/contrib/mercurial.el	Wed Aug 31 18:25:07 2005
@@ -283,13 +283,13 @@
     (replace-regexp-in-string regexp newtext str nil literal)))
 
 (defsubst hg-strip (str)
-  "Strip leading and trailing white space from a string."
-  (hg-replace-in-string (hg-replace-in-string str "[ \t\r\n]+$" "")
-			"^[ \t\r\n]+" ""))
+  "Strip leading and trailing blank lines from a string."
+  (hg-replace-in-string (hg-replace-in-string str "[\r\n][ \t\r\n]*\\'" "")
+			"\\`[ \t\r\n]*[\r\n]" ""))
 
 (defsubst hg-chomp (str)
   "Strip trailing newlines from a string."
-  (hg-replace-in-string str "[\r\n]+$" ""))
+  (hg-replace-in-string str "[\r\n]+\'" ""))
 
 (defun hg-run-command (command &rest args)
   "Run the shell command COMMAND, returning (EXIT-CODE . COMMAND-OUTPUT).


More information about the Mercurial mailing list