There are many project description files using a quite neat structure like this:





My question is: Is there any convenient ways to generate automatically the title using such structure as:


, where the number of Equal Sign(=) is well aligned to the that of characters of the title just preceding it.

  • Write your file in Org mode and export as text?
    – NickD
    May 22, 2022 at 11:03

2 Answers 2


The documentation for yasnippet gives almost exactly this workflow as an example of its "field mirroring" capabilities. That's for entering titles; it might be possible to adapt it to edit existing well-structured text too.

For example, with the following snippet, press C-c u and start typing. When you're done, press TAB.

# -*- mode: snippet -*-
# name: underline
# binding : C-c u
# --
${1:$(make-string (string-width yas-text) ?\=)}

  • Thank you @jagrg. It seems unfair that I can't upvote you for such a substantive assist. May 22, 2022 at 16:07

You can use the following command to underline the line at point.

(defun underline ()
  (let* ((line (string-trim (thing-at-point 'line t)))
         (underline (make-string (string-width line) ?\=))
         (padding (save-excursion
                    (forward-line 0)
                    (when (re-search-forward "[^ ]" (point-at-eol) t)
                      (make-string (1- (current-column)) ?\s)))))
    (unless (string-empty-p underline)    
      (insert (format "\n%s%s\n\n" padding underline)))))
  • Thanks! The solution just works perfectly as well! Would definitely upvote for it if I have enough SE Reputation.
    – absuu
    May 27, 2022 at 8:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.