emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/logos 8c2e85033d 2/3: Improve how pages/outlines are ha


From: ELPA Syncer
Subject: [elpa] externals/logos 8c2e85033d 2/3: Improve how pages/outlines are handled when narrow
Date: Mon, 21 Mar 2022 01:57:33 -0400 (EDT)

branch: externals/logos
commit 8c2e85033db982ef13a5e041012dc45d86d9de32
Author: Omar AntolĂ­n Camarena <omar@matem.unam.mx>
Commit: Protesilaos Stavrou <info@protesilaos.com>

    Improve how pages/outlines are handled when narrow
    
    1. If logos-outlines-are-pages is non-nil, it now includes the match of
    the page-delimiter regexp in the narrowed region and leaves point right
    after the page-delimiter ---so in Org mode, after the stars.  (I thought
    it was better to leave point there than at the very beginning of the
    narrowed buffer to match the behavior of logos-forward-page-dwim when
    the buffer is not narrowed.)
    
    2. To avoid skipping pages in the narrowed case, the function checks if
    you are right at the start of a page-delimiter and if so move you past
    the delimiter in the opposite direction you are moving: so if you are
    moving back, it puts you after the delimiter, and if you are moving
    forward it puts you before the delimiter.  (The bug was that if the
    point was at point-max while narrowed and moving forward, it would skip
    past a page and the same in the opposite direction with point-min.)
    
    3. Changed logos-narrow-dwim to call logos--narrow-to-page instead of
    narrow-to-page, so that it too includes the page-delimiter match in the
    page.
---
 logos.el | 32 +++++++++++++++++++++++++++++---
 1 file changed, 29 insertions(+), 3 deletions(-)

diff --git a/logos.el b/logos.el
index 4c4e89fa32..7d1b2d8559 100644
--- a/logos.el
+++ b/logos.el
@@ -166,11 +166,34 @@ This is only relevant when `logos-focus-mode' is enabled."
 
 (defun logos--narrow-to-page (count &optional back)
   "Narrow to COUNTth page with optional BACK motion."
+  ;; Position point to avoid skipping pages.
+  (when (and (buffer-narrowed-p)
+             (save-restriction
+               (widen)
+               (looking-at page-delimiter)))
+    (goto-char (if back
+                   (1+ (match-end 0))
+                 (1- (match-beginning 0)))))
   (if back
       (narrow-to-page (or (- count) -1))
     (narrow-to-page (or (abs count) 1)))
-  ;; Avoids the problem of skipping pages while cycling back and forth.
-  (goto-char (point-min)))
+  (let ((page-start (point-min-marker)))
+    ;; If outlines are pages, include match of page-delimiter in page
+    (when (and logos-outlines-are-pages
+               (save-excursion
+                 (goto-char (point-min))
+                 (save-restriction
+                   (widen)
+                   (looking-back page-delimiter (line-beginning-position)))))
+      (let ((match-start (match-beginning 0))
+            (page-end (point-max-marker)))
+        (widen)
+        (narrow-to-region match-start page-end)))
+    ;; Leave point at a standard location: if outlines are pages,
+    ;; leave it right after the page-delimiter (to match the
+    ;; unnarrowed behavior); if outlines are not pages, leave it at
+    ;; the beginning of the page.
+    (goto-char page-start)))
 
 (defvar logos-page-motion-hook nil
   "Hook that runs after a page motion.
@@ -272,7 +295,10 @@ If narrowing is in effect, widen the view."
          (null (buffer-narrowed-p)))
     (narrow-to-region (region-beginning) (region-end)))
    ((logos--page-p)
-    (narrow-to-page))
+    ;; Use our own narrow to page function because when
+    ;; logos-outlines-are-pages is t, the page delimiter
+    ;; is included in the region narrowed to.
+    (logos--narrow-to-page 0))
    ((null (buffer-narrowed-p))
     (logos-narrow-visible-window))
    ((widen))))



reply via email to

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