From: Mark Wooding Date: Thu, 20 Dec 2012 12:25:30 +0000 (+0000) Subject: el/dot-emacs.el: Respect `indent-tabs-mode' when computing fill prefix. X-Git-Url: https://git.distorted.org.uk/~mdw/profile/commitdiff_plain/cd07f97f522053f9adf2901967e2b7f5596f1cf5 el/dot-emacs.el: Respect `indent-tabs-mode' when computing fill prefix. This is basically a rewrite of `mdw-tabify', to make it cleaner, and respect the variable setting. --- diff --git a/el/dot-emacs.el b/el/dot-emacs.el index ec96175..2909fdd 100644 --- a/el/dot-emacs.el +++ b/el/dot-emacs.el @@ -645,21 +645,15 @@ This is mainly useful in `auto-fill-mode'.") ;; 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 @@ context and return the static fill prefix to use. Point must be 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)