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

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

Re: Underline the current line (function inside)


From: Jean Louis
Subject: Re: Underline the current line (function inside)
Date: Fri, 11 Jun 2021 18:33:45 +0300
User-agent: Mutt/2.0.7+183 (3d24855) (2021-05-28)

* Eli Zaretskii <eliz@gnu.org> [2021-06-11 17:53]:
> > Date: Fri, 11 Jun 2021 17:32:26 +0300
> > From: Jean Louis <bugs@gnu.support>
> > 
> > This function is handy to underline the current line:
> > 
> > (defun underline-line ()
> >   "Underline the current line."
> >   (interactive)
> >   (let* ((start (line-beginning-position))
> >      (end (line-end-position))
> >      (length (- end start)))
> >     (end-of-line)
> >     (newline)
> >     (insert (make-string length ?=))
> >     (newline)))
> 
> This assumes that each character takes 1 column.  That is false in
> general, because some characters have zero width on display, and some
> others take closer to two columns.
> 
> You need to use string-width instead, or count columns instead of
> buffer positions.
> 
> And, of course, all this assumes fixed-pitch font.

Thanks.

(defun underline-line ()
  "Underline the current line."
  (interactive)
  (let* ((start (line-beginning-position))
         (end (line-end-position))
         (length (string-width (buffer-substring-no-properties start end))))
    (end-of-line)
    (newline)
    (insert (make-string length ?=))
    (newline)))




reply via email to

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