From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Cecil Westerhof Newsgroups: gmane.emacs.help Subject: underline-line Date: Thu, 24 Dec 2009 12:06:45 +0100 Organization: Decebal Computing Message-ID: <87k4wc7hru.fsf@Traian.DecebalComp> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; format=flowed X-Trace: ger.gmane.org 1261654852 29109 80.91.229.12 (24 Dec 2009 11:40:52 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 24 Dec 2009 11:40:52 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Dec 24 12:40:45 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1NNm3g-0000Au-G3 for geh-help-gnu-emacs@m.gmane.org; Thu, 24 Dec 2009 12:40:44 +0100 Original-Received: from localhost ([127.0.0.1]:40583 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NNm3g-00058h-ME for geh-help-gnu-emacs@m.gmane.org; Thu, 24 Dec 2009 06:40:44 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.84.MISMATCH!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Original-Newsgroups: gnu.emacs.help Set: dutch X-Homepage: http://www.decebal.nl/ User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.3 (gnu/linux) Cancel-Lock: sha1:ZftS7Rov9f1roq+ZOKzT9r1ibMM= Original-Lines: 55 Original-NNTP-Posting-Host: 84.53.123.169 Original-X-Trace: 1261652805 news.xs4all.nl 22916 decebal/[::ffff:84.53.123.169]:23933 Original-X-Complaints-To: abuse@xs4all.nl Original-Xref: news.stanford.edu gnu.emacs.help:175764 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:70840 Archived-At: 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