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

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

[nongnu] elpa/popup 88efff5 010/184: Not to insert newlines.


From: ELPA Syncer
Subject: [nongnu] elpa/popup 88efff5 010/184: Not to insert newlines.
Date: Wed, 6 Oct 2021 00:00:57 -0400 (EDT)

branch: elpa/popup
commit 88efff5098f333dfe6d9ea7191afefbf3265bb6f
Author: Tomohiro Matsuyama <tomo@cx4a.org>
Commit: Tomohiro Matsuyama <tomo@cx4a.org>

    Not to insert newlines.
---
 popup.el | 42 ++++++++++++++++++++++--------------------
 1 file changed, 22 insertions(+), 20 deletions(-)

diff --git a/popup.el b/popup.el
index 8a50293..fbf1bee 100644
--- a/popup.el
+++ b/popup.el
@@ -239,7 +239,7 @@ buffer."
   parent depth
   face mouse-face selection-face
   margin-left margin-right margin-left-cancel scroll-bar symbol
-  cursor offset scroll-top current-height list newlines
+  cursor offset scroll-top current-height list padding
   pattern original-list)
 
 (defun popup-item-propertize (item &rest properties)
@@ -393,7 +393,7 @@ usual."
     (unless (overlay-get overlay 'dangle)
       (overlay-put overlay 'display (concat prefix (substring content 0 1)))
       (setq prefix nil
-            content (concat (substring content 1))))
+            content (substring content 1)))
     (overlay-put overlay
                  'after-string
                  (concat prefix
@@ -523,13 +523,15 @@ KEYMAP is a keymap that will be put on the popup 
contents."
                        ;; Calculate direction
                        (popup-calculate-direction height row)))
            (depth (if parent (1+ (popup-depth parent)) 0))
-           (newlines (max 0 (+ (- height (count-lines point (point-max))) (if 
around 1 0))))
+           padding
            current-column)
-      ;; Case: no newlines at the end of the buffer
-      (when (> newlines 0)
+      ;; Case: no room to put overlays
+      (when (eobp)
         (popup-save-buffer-state
-          (goto-char (point-max))
-          (insert (make-string newlines ?\n))))
+          (let ((begin (point)))
+            (insert " ")
+            (setq padding (make-overlay begin (point)))
+            (overlay-put padding 'evaporate t))))
       
       ;; Case: the popup overflows
       (if overflow
@@ -554,11 +556,11 @@ KEYMAP is a keymap that will be put on the popup 
contents."
         (setq margin-left-cancel t))
       
       (dotimes (i height)
-        (let (overlay begin w (dangle t) (prefix "") (postfix ""))
+        (let (overlay begin w bottom (dangle t) (prefix "") (postfix ""))
           (when around
-            (popup-vertical-motion column direction))
-         (setq around t
-                current-column (popup-current-physical-column))
+            (setq bottom (zerop (popup-vertical-motion column direction))))
+         (setq around t)
+          (setq current-column (if bottom 0 (popup-current-physical-column)))
 
           (when (> current-column column)
             (backward-char)
@@ -566,7 +568,8 @@ KEYMAP is a keymap that will be put on the popup contents."
           (when (< current-column column)
             ;; Extend short buffer lines by popup prefix (line of spaces)
             (setq prefix (make-string
-                          (+ (if (= current-column 0)
+                          (+ (if (and (not bottom)
+                                      (= current-column 0))
                                  (- window-hscroll (current-column))
                                0)
                              (- column current-column))
@@ -574,6 +577,8 @@ KEYMAP is a keymap that will be put on the popup contents."
 
           (setq begin (point))
           (setq w (+ popup-width (length prefix)))
+          (when bottom
+            (setq prefix (concat "\n" prefix)))
           (while (and (not (eolp)) (> w 0))
             (setq dangle nil)
             (decf w (char-width (char-after)))
@@ -581,6 +586,7 @@ KEYMAP is a keymap that will be put on the popup contents."
           (if (< w 0)
               (setq postfix (make-string (- w) ? )))
 
+
           (setq overlay (make-overlay begin (point)))
           (overlay-put overlay 'window window)
           (overlay-put overlay 'dangle dangle)
@@ -615,7 +621,7 @@ KEYMAP is a keymap that will be put on the popup contents."
                             :scroll-top 0
                             :current-height 0
                             :list nil
-                            :newlines newlines
+                            :padding padding
                             :overlays overlays
                             :keymap keymap)))
         (push it popup-instances)
@@ -628,14 +634,10 @@ KEYMAP is a keymap that will be put on the popup 
contents."
     (mapc 'delete-overlay (popup-overlays popup))
     (setf (popup-overlays popup) nil)
     (setq popup-instances (delq popup popup-instances))
-    ;; Restore newlines state
-    (let ((newlines (popup-newlines popup)))
-      (when (> newlines 0)
+    (let ((padding (popup-padding popup)))
+      (when (overlayp padding)
         (popup-save-buffer-state
-          (goto-char (point-max))
-          (dotimes (i newlines)
-            (if (= (char-before) ?\n)
-                (delete-char -1)))))))
+          (delete-region (overlay-start padding) (overlay-end padding))))))
   nil)
 
 (defun popup-draw (popup)



reply via email to

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