~protesilaos/logos

fcc13bf490673eaa6700c16645f3d90b87350927 — Protesilaos Stavrou 1 year, 5 months ago af64c19
Make logos-page-delimiter function and variable public

This is because they may be used in custom code that is defined at the
user level.  We want them to be "public" to suggest that they are safe
to use: their behaviour is predictable, while any breaking changes
will be documented.
2 files changed, 23 insertions(+), 13 deletions(-)

M README.org
M logos.el
M README.org => README.org +7 -7
@@ 442,12 442,12 @@ outline and the page delimiters:

#+begin_src emacs-lisp
(setq logos-outline-regexp-alist
      `((emacs-lisp-mode . ,(format "\\(^;;;+ \\|%s\\)" (default-value 'page-delimiter)))
        (org-mode . ,(format "\\(^\\*+ +\\|%s\\)" (default-value 'page-delimiter)))))
      `((emacs-lisp-mode . ,(format "\\(^;;;+ \\|%s\\)" logos-page-delimiter))
        (org-mode . ,(format "\\(^\\*+ +\\|%s\\)" logos-page-delimiter))))
#+end_src

The form =,(format "\\(^;;;+ \\|%s\\)" logos--page-delimiter)= expands
to ="\\(^;;;+ \\|^\\)"=.
The form =,(format "\\(^;;;+ \\|%s\\)" logos-page-delimiter)=

For Org it may be better to either not target the =^L= or to also target
the horizontal rule (five hyphens on a line, else the =^-\\{5\\}$=


@@ 455,8 455,8 @@ pattern).  Putting it all together:

#+begin_src emacs-lisp
(setq logos-outline-regexp-alist
      `((emacs-lisp-mode . ,(format "\\(^;;;+ \\|%s\\)" logos--page-delimiter))
        (org-mode . ,(format "\\(^\\*+ +\\|^-\\{5\\}$\\|%s\\)" logos--page-delimiter))))
      `((emacs-lisp-mode . ,(format "\\(^;;;+ \\|%s\\)" logos-page-delimiter))
        (org-mode . ,(format "\\(^\\*+ +\\|^-\\{5\\}$\\|%s\\)" logos-page-delimiter))))
#+end_src

Another Org-specific tweak is to use heading levels up to a specific


@@ 468,8 468,8 @@ end result can look like this:

#+begin_src emacs-lisp
(setq logos-outline-regexp-alist
      `((emacs-lisp-mode . ,(format "\\(^;;;+ \\|%s\\)" logos--page-delimiter))
        (org-mode . ,(format "\\(^\\*\\{1,3\\} +\\|^-\\{5\\}$\\|%s\\)" logos--page-delimiter))))
      `((emacs-lisp-mode . ,(format "\\(^;;;+ \\|%s\\)" logos-page-delimiter))
        (org-mode . ,(format "\\(^\\*\\{1,3\\} +\\|^-\\{5\\}$\\|%s\\)" logos-page-delimiter))))
#+end_src

** Leverage logos-focus-mode-hook

M logos.el => logos.el +16 -6
@@ 231,14 231,19 @@ and disabled, then use the `logos-focus-mode-hook' instead."

;;;; Page motions

(defconst logos--page-delimiter (default-value 'page-delimiter)
(define-obsolete-variable-alias
  'logos--page-delimiter
  'logos-page-delimiter
  "1.1.0")

(defconst logos-page-delimiter (default-value 'page-delimiter)
  "The default value of `page-delimiter'.")

(defun logos--outline-or-delimiter ()
  "Return the current `outline-regexp' or page delimiter."
  (if (bound-and-true-p outline-regexp)
      outline-regexp
    logos--page-delimiter))
    logos-page-delimiter))

(defun logos--outline-regexp ()
  "Return page delimiter from `logos-outline-regexp-alist'."


@@ 248,11 253,16 @@ and disabled, then use the `logos-focus-mode-hook' instead."
        (alist-get (get mode 'derived-mode-parent) outline)
        (logos--outline-or-delimiter))))

(defun logos--page-delimiter ()
(define-obsolete-function-alias
  'logos--page-delimiter
  'logos-page-delimiter
  "1.1.0")

(defun logos-page-delimiter ()
  "Determine the `page-delimiter'."
  (if logos-outlines-are-pages
      (setq-local page-delimiter (logos--outline-regexp))
    (setq-local page-delimiter logos--page-delimiter)))
    (setq-local page-delimiter logos-page-delimiter)))

(defun logos--narrow-to-page (count &optional back)
  "Narrow to COUNTth page with optional BACK motion."


@@ 294,7 304,7 @@ See `logos-forward-page-dwim' or `logos-backward-page-dwim'.")
With optional numeric COUNT move by that many pages.  With
optional BACK perform the motion backwards."
  (let ((cmd (if back #'backward-page #'forward-page)))
    (logos--page-delimiter)
    (logos-page-delimiter)
    (if (buffer-narrowed-p)
        (logos--narrow-to-page count back)
      (funcall cmd count)


@@ 349,7 359,7 @@ page."
  "Return non-nil if there is a `page-delimiter' in the buffer.
This function does not use `widen': it only checks the accessible
portion of the buffer."
  (let ((delimiter (logos--page-delimiter)))
  (let ((delimiter (logos-page-delimiter)))
    (or (save-excursion (re-search-forward delimiter nil t))
        (save-excursion (re-search-backward delimiter nil t)))))