help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

underline-line


From: Cecil Westerhof
Subject: underline-line
Date: Thu, 24 Dec 2009 12:06:45 +0100
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.3 (gnu/linux)

Sometime you want to underline a sentence, just like this one. -------------------------------------------------------------- That is why I wrote a function underline-line. (Good name giving to functions and files will be done soon.) Default it underlines the complete line with '-'. An example with white-space at the front and end. ------------------------------------------------------------ But the default underline character can be changed: (underline-line ?^) gives: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ But not underlining the white-space could be useful. That is possible with (underline-line nil t): --------------------------------------------- And of course the underline character can still be changed: (underline-line ?* t) gives: **************************** There is a problem with tabs as seen here: ------------------------------------------ Also what is a better default: underlining everything as is done now, or is it better to default not underline the white-space at the beginning and the end of the line? I am open to suggestions. The code (own-functions-general.el on http://www.decebal.nl/EmacsLisp/): (defun underline-line (&optional underline-char skip-outer-whitespace) "Underline current line; Default the whole line is underlined with -. If underline-char is given, this character is used. When skip-outer-whitespace is not nil, whitespace at the beginning and the end of the line is not underlined. When there are characters that do not have a width of one, this function will not work correctly. This is the case with tabs. If the tabs are only in the whitespace at the beginning of the line, this function works correctly."
     (interactive)
     (save-excursion
(let ((end-point) (start-point) (start-string "") (this-underline-char) (underline-length)) (if (char-valid-p underline-char) (setq this-underline-char underline-char) (setq this-underline-char "-")) (end-of-line) (setq end-point (point)) (beginning-of-line) (setq start-point (point)) (when skip-outer-whitespace (if (not (re-search-forward "\\(^[ \t]*\\)[^ \t]" end-point)) (setq start-point end-point) (setq start-point (match-end 0) start-string (match-string 1)) (end-of-line) (re-search-backward "\\([^ \t]\\)[ \t]*$" start-point) (setq end-point (1+ (match-end 1))))) (setq underline-length (- end-point start-point)) (if (< underline-length 1) (exit-depends-on-interactive "Nothing to underline" (interactive-p))
           (forward-line 1) (insert start-string) (loop for i
           from 1 to underline-length do (insert
           this-underline-char)) (insert "\n")))))

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof


reply via email to

[Prev in Thread] Current Thread [Next in Thread]