Skip to content

A clean interface for org files (Emacs)

License

Notifications You must be signed in to change notification settings

frumigoul/book-mode

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

./book-mode.png

Book mode - Nicolas Rougier - January 9, 2023 (WIP)

Book mode is an attempt at offering an interface for reading org-mode files with a clean layout. It is based on the use of large margins, headline and mode-line, with leading stars and bullets in the left margin using right alignment and different symbols. All decorations are part of the header-line (including upper left colored part and right upper glyph) and messages are displayed in the mode-line.

See also inside article directory for a more advanced and experimental example.

Section

Using font lock keywords, we can have outer indent by moving leading stars into the left margin such that text is always aligned. This could be extended to org-num-mode but it would require a bigger margin and dedicated regex. This is applied for level 1, 2 and 3 while level 4 has a special transformation to make it appear like a paragraph (see below).

Subsection

Using the same trick, we can also move list bullets in the margin and use a nicer glyph (“•” instead of “-“):

  • Item 1
  • Item 2

Not everyone like to have bullets in the margin though.

Subsubsection

The hl-line has been extended to margins such that it goes from side to side and plays nicely with leading stars and bullets.

Paragraph

This is actually a fourth level heading with a special keyword that suppress the (first) line jump. This results in the first paragraph to immediately follows the heading (like a paragraph in LaTeX).

(when (derived-mode-p 'org-mode)
  (add-to-list 'font-lock-extra-managed-props 'display)
  ;;(setq left-margin 5)
  ;;(setq left-margin-width left-margin)
  ;;(set-window-margins (selected-window) left-margin 0)
  (let ((margin-format (format "%%%ds" left-margin-width)))
    (font-lock-add-keywords nil
       `(
         ("^\\(\\- \\)\\(.*\\)$"
          1 '(face nano-default display ((margin left-margin)
                                         ,(propertize (format margin-format "")
                                                      'face '(:inherit nano-default :weight light)) append)))

         ("^\\(\\*\\{1\\} \\)\\(.*\\)$"
          1 '(face nano-faded display ((margin left-margin)
                                       ,(propertize (format margin-format "# ")
                                                    'face '(:inherit nano-faded :weight light)) append))
          2 '(face bold append))

         ("^\\(\\*\\{2\\} \\)\\(.*\\)$"
          1 '(face nano-faded display ((margin left-margin)
                                       ,(propertize (format margin-format "## ")
                                                    'face '(:inherit nano-faded :weight light)) append))
          2 '(face bold append))

         ("^\\(\\*\\{3\\} \\)\\(.*\\)$"
          1 '(face nano-faded display ((margin left-margin)
                                       ,(propertize (format margin-format "### ")
                                                    'face '(:inherit nano-faded :weight light)) append))
          2 '(face bold append))

         ("^\\*\\{4\\} .*?\\(\n\\)"
          1 '(face nil display " - "))

         ("^\\(\\*\\{4\\} \\)\\(.*?\\)$"
          1 '(face nano-faded display ((margin left-margin)
                                       ,(propertize (format margin-format "§ ")
                                                    'face '(:inherit nano-faded :weight light))  append))
          2 '(face bold append)))))

  (font-lock-fontify-buffer)
  ;; (visual-line-mode)
  )

About

A clean interface for org files (Emacs)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Emacs Lisp 76.2%
  • TeX 23.8%