unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Cecil Westerhof <Cecil@decebal.nl>
To: help-gnu-emacs@gnu.org
Subject: underline-line
Date: Thu, 24 Dec 2009 12:06:45 +0100	[thread overview]
Message-ID: <87k4wc7hru.fsf@Traian.DecebalComp> (raw)

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	other threads:[~2009-12-24 11:06 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-24 11:06 Cecil Westerhof [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87k4wc7hru.fsf@Traian.DecebalComp \
    --to=cecil@decebal.nl \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).