unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* underline-line
@ 2009-12-24 11:06 Cecil Westerhof
  2009-12-24 11:23 ` underline-line Cecil Westerhof
  2009-12-24 15:32 ` underline-line Pascal J. Bourguignon
  0 siblings, 2 replies; 12+ messages in thread
From: Cecil Westerhof @ 2009-12-24 11:06 UTC (permalink / raw)
  To: help-gnu-emacs

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


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2009-12-26  9:21 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-24 11:06 underline-line Cecil Westerhof
2009-12-24 11:23 ` underline-line Cecil Westerhof
2009-12-24 12:21   ` underline-line Reiner Steib
2009-12-24 12:50     ` underline-line Cecil Westerhof
2009-12-24 15:32 ` underline-line Pascal J. Bourguignon
2009-12-25  5:59   ` underline-line tomas
2009-12-25  6:33   ` underline-line Cecil Westerhof
2009-12-25 23:07     ` underline-line Tim X
2009-12-25 23:52       ` underline-line Pascal J. Bourguignon
2009-12-26  7:03         ` underline-line Tim X
2009-12-26  9:21       ` underline-line Cecil Westerhof
     [not found]   ` <mailman.167.1261721014.18930.help-gnu-emacs@gnu.org>
2009-12-25 22:57     ` underline-line Tim X

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).