chiark / gitweb /
el/dot-emacs.el: Respect `indent-tabs-mode' when computing fill prefix.
authorMark Wooding <mwooding@good.com>
Thu, 20 Dec 2012 12:25:30 +0000 (12:25 +0000)
committerMark Wooding <mwooding@good.com>
Thu, 20 Dec 2012 14:44:01 +0000 (14:44 +0000)
This is basically a rewrite of `mdw-tabify', to make it cleaner, and
respect the variable setting.

el/dot-emacs.el

index ec961750088c803c23bcb0a2eb93fa4c3f366e95..2909fdd67da388047d2e61635922e86f610bfa8d 100644 (file)
@@ -645,21 +645,15 @@ (fset 'mdw-do-auto-fill (symbol-function 'do-auto-fill))
 
 ;; Utility functions.
 
-(defun mdw-tabify (s)
-  "Tabify the string S.  This is a horrid hack."
-  (save-excursion
+(defun mdw-maybe-tabify (s)
+  "Tabify or untabify the string S, according to `indent-tabs-mode'."
+  (with-temp-buffer
     (save-match-data
-      (let (start end)
-       (beginning-of-line)
-       (setq start (point-marker))
+      (let ((tabfun (if indent-tabs-mode #'tabify #'untabify)))
        (insert s "\n")
-       (setq end (point-marker))
-       (tabify start end)
-       (setq s (buffer-substring start (1- end)))
-       (delete-region start end)
-       (set-marker start nil)
-       (set-marker end nil)
-       s))))
+       (let ((start (point-min)) (end (point-max)))
+         (funcall tabfun start end)
+         (setq s (buffer-substring start (1- end))))))))
 
 (defun mdw-examine-fill-prefixes (l)
   "Given a list of dynamic fill prefixes, pick one which matches
@@ -667,9 +661,9 @@ (defun mdw-examine-fill-prefixes (l)
 at the start of a line, and match data must be saved."
   (cond ((not l) nil)
               ((looking-at (car (car l)))
-               (mdw-tabify (apply #'concat
-                                  (mapcar #'mdw-do-prefix-match
-                                          (cdr (car l))))))
+               (mdw-maybe-tabify (apply #'concat
+                                        (mapcar #'mdw-do-prefix-match
+                                                (cdr (car l))))))
               (t (mdw-examine-fill-prefixes (cdr l)))))
 
 (defun mdw-maybe-car (p)