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

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

[nongnu] elpa/popon 51c71ea681 1/2: Make lines no longer than 75 charact


From: ELPA Syncer
Subject: [nongnu] elpa/popon 51c71ea681 1/2: Make lines no longer than 75 characters
Date: Sat, 8 Oct 2022 07:58:57 -0400 (EDT)

branch: elpa/popon
commit 51c71ea6816753bccf4050434099e27e7ba1659d
Author: Akib Azmain Turja <akib@disroot.org>
Commit: Akib Azmain Turja <akib@disroot.org>

    Make lines no longer than 75 characters
---
 README.org |  20 +++----
 popon.el   | 173 +++++++++++++++++++++++++++++++++++--------------------------
 2 files changed, 110 insertions(+), 83 deletions(-)

diff --git a/README.org b/README.org
index 1f7b70b1ae..da820e7cdb 100644
--- a/README.org
+++ b/README.org
@@ -1,9 +1,9 @@
 #+title: Popon - "Pop" floating text "on" a window
 
-Popon allows you to pop text on a window, what we call a popon.  Popons are
-window-local and sticky, they don't move while scrolling, and they even
-don't go away when switching buffer, but you can bind a popon to a specific
-buffer to only show on that buffer.
+Popon allows you to pop text on a window, what we call a popon.
+Popons are window-local and sticky, they don't move while scrolling,
+and they even don't go away when switching buffer, but you can bind a
+popon to a specific buffer to only show on that buffer.
 
 If some popons are annoying you and you can't kill them, do
 =M-x popon-kill-all= to kill all popons.
@@ -34,9 +34,9 @@ Download =popon.el= and put it in your ~load-path~.
 
 * Usage
 
-The main entry point is ~popon-create~, which creates a popon and returns
-that.  Use ~popon-kill~ to kill it.  Popons are immutable, you can't modify
-them.  Most of time you'll want to place the popon at certain point of
-buffer; call ~popon-x-y-at-pos~ with the point and use the return value as
-the coordinates.  Be sure see the docstring of each function, they describe
-the best.
+The main entry point is ~popon-create~, which creates a popon and
+returns that.  Use ~popon-kill~ to kill it.  Popons are immutable, you
+can't modify them.  Most of time you'll want to place the popon at
+certain point of buffer; call ~popon-x-y-at-pos~ with the point and
+use the return value as the coordinates.  Be sure see the docstring of
+each function, they describe the best.
diff --git a/popon.el b/popon.el
index 727842a14a..b9538c6257 100644
--- a/popon.el
+++ b/popon.el
@@ -26,10 +26,11 @@
 
 ;;; Commentary:
 
-;; Popon allows you to pop text on a window, what we call a popon.  Popons
-;; are window-local and sticky, they don't move while scrolling, and they
-;; even don't go away when switching buffer, but you can bind a popon to a
-;; specific buffer to only show on that buffer.
+;; Popon allows you to pop text on a window, what we call a popon.
+;; Popons are window-local and sticky, they don't move while
+;; scrolling, and they even don't go away when switching buffer, but
+;; you can bind a popon to a specific buffer to only show on that
+;; buffer.
 
 ;; If some popons are annoying you and you can't kill them, do M-x
 ;; popon-kill-all to kill all popons.
@@ -41,16 +42,18 @@
 
 (defun popon--render-lines (framebuffer x y lines width)
   "Place LINES on top of FRAMEBUFFER.
-Place LINES on top of text at line X and column Y on FRAMEBUFFER and return
-FRAMEBUFFER.  LINES is a list of list as string.  FRAMEBUFFER is a list,
-each element is of form: (LINE MODIFIED EXTENDED OTHERS...), where LINE is
-as string, MODIFIED is t when LINE is modified and EXTENDED is t when the
-line has been extended.  OTHERS is not modified in any way.  Each line in
-LINES is assumed to occupy WIDTH character.  FRAMEBUFFER and LINES
-shouldn't contain newlines.  Example:
+
+Place LINES on top of text at line X and column Y on FRAMEBUFFER and
+return FRAMEBUFFER.  LINES is a list of list as string.  FRAMEBUFFER
+is a list, each element is of form: (LINE MODIFIED EXTENDED
+OTHERS...), where LINE is as string, MODIFIED is t when LINE is
+modified and EXTENDED is t when the line has been extended.  OTHERS is
+not modified in any way.  Each line in LINES is assumed to occupy
+WIDTH character.  FRAMEBUFFER and LINES shouldn\\='t contain newlines.
+Example:
 
 \(`popon--render-lines'
- '((\"GNU Emacs is “free software”; this means\" nil nil)
+ \\='((\"GNU Emacs is “free software”; this means\" nil nil)
    (\"that everyone is free to use it and free\" nil nil)
    (\"to redistribute it under certain\"         nil nil)
    (\"conditions.  GNU Emacs is not in the\"     nil nil)
@@ -66,7 +69,7 @@ shouldn't contain newlines.  Example:
    (\"found in the GNU General Public License\"  nil nil)
    (\"that comes with Emacs and also appears\"   nil nil)
    (\"in this manual(1).  See Copying.\"         t nil))
- 11 1 '(\"+--^^^^^^^^^^^^^-------------------------+\"
+ 11 1 \\='(\"+--^^^^^^^^^^^^^-------------------------+\"
         \"|Free software is a type of software that|\"
         \"|respects user freedom.  Think free as in|\"
         \"|free speech, not as in free beer.       |\"
@@ -89,7 +92,8 @@ shouldn't contain newlines.  Example:
     (\"that comes with Emacs and also appears\"                nil nil)
     (\"in this manual(1).  See Copying.\"                      t nil))"
   (let ((tab-size tab-width)
-        (inhibit-read-only t)) ; The text might have `read-only' property.
+        ;; The text might have `read-only' property.
+        (inhibit-read-only t))
     (with-temp-buffer
       (setq-local tab-width tab-size) ; Preseve tab width.
       (dotimes (i (length lines))
@@ -135,9 +139,10 @@ shouldn't contain newlines.  Example:
 ;;;###autoload
 (defun popon-put (popon prop value)
   "Set the PROP property of popon POPON to VALUE."
-  (setcdr popon (plist-put (cdr popon)
-                           :plist (plist-put (plist-get (cdr popon) :plist)
-                                             prop value))))
+  (setcdr popon
+          (plist-put (cdr popon) :plist
+                     (plist-put (plist-get (cdr popon) :plist)
+                                prop value))))
 
 ;;;###autoload
 (defun popon-properties (popon)
@@ -190,7 +195,8 @@ Return nil if popon POPON is killed."
 (defun popon-text (popon)
   "Return the text popon POPON is displaying.
 
-POPON may be a killed popon.  Return nil if POPON isn't a popon at all."
+POPON may be a killed popon.  Return nil if POPON isn't a popon at
+all."
   (when (poponp popon)
     (mapconcat #'identity (plist-get (cdr popon) :lines) "\n")))
 
@@ -209,14 +215,14 @@ POPON may be a killed popon.  Return nil if POPON isn't a 
popon at all."
 Display popon only if WINDOW is displaying BUFFER.
 
 POS is a cons (X, Y), where X is column and Y is line in WINDOW.  TEXT
-should be a string or a cons cell of form (STR . WIDTH).  When TEXT is a
-string, each line of it should be of same length (i.e `string-width' should
-return the same length for every line).  When TEXT is a cons cell, STR is
-used as the text to display and each line of it should be of visual length
-width.
-
-PRIORITY is a number (integer or float) between -100 and 100.  Popons with
-larger priority values are rendered first."
+should be a string or a cons cell of form (STR . WIDTH).  When TEXT is
+a string, each line of it should be of same length (i.e `string-width'
+should return the same length for every line).  When TEXT is a cons
+cell, STR is used as the text to display and each line of it should be
+of visual length width.
+
+PRIORITY is a number (integer or float) between -100 and 100.  Popons
+with larger priority values are rendered first."
   (when (not (or (consp text) (stringp text)))
     (signal 'wrong-type-argument
             `((or (consp text) (stringp text)) ,text)))
@@ -259,16 +265,17 @@ Do nothing if POPON isn't a live popon.  Return nil."
 (defvar-local popon--line-beginnings nil
   "List of line beginning of current buffer.
 
-The value is of form (TICK . LINE-BEGINNINGS), where LINE-BEGINNINGS is the
-sorted list of beginning of lines and TICK is the value of tick counter
-when LINE-BEGINNINGS was calculated.")
+The value is of form (TICK . LINE-BEGINNINGS), where LINE-BEGINNINGS
+is the sorted list of beginning of lines and TICK is the value of tick
+counter when LINE-BEGINNINGS was calculated.")
 
 (defun popon--buffer-visible-substring (start end)
-  "Return the visible contents of part of the current buffer as a string.
+  "Return the visible contents of part of the current buffer.
 
 Take the `invisible' text property into account.
 
-START and END specifies which part to return.  They can be in any order."
+START and END specifies which part to return.  They can be in any
+order."
   (when (> start end)
     (let ((tmp end))
       (setq end start)
@@ -282,28 +289,30 @@ START and END specifies which part to return.  They can 
be in any order."
                             (point) 'invisible nil end)))
           (cond
            ((null prop)
-            (setq str (concat str (buffer-substring (point) next-change))))
+            (setq str (concat str (buffer-substring
+                                   (point) next-change))))
            ((and (consp buffer-invisibility-spec)
                  (member (cons prop t) buffer-invisibility-spec))
-            (setq str (concat str (apply #'propertize "..." 'invisible nil
-                                         (text-properties-at (point)))))))
+            (setq str
+                  (concat str (apply #'propertize "..." 'invisible nil
+                                     (text-properties-at (point)))))))
           (goto-char next-change))))
     str))
 
 (defun popon--make-framebuffer ()
   "Create a framebuffer for current window and buffer."
   (let ((framebuffer nil)
-        (line-boundaries (let ((pair popon--line-beginnings)
-                               (boundaries nil))
-                           (when (eq (car pair) (buffer-modified-tick))
-                             (setq pair (cdr pair))
-                             (while pair
-                               (when (and (integerp (car pair))
-                                          (integerp (cadr pair)))
-                                 (push (cons (car pair) (cadr pair))
-                                       boundaries))
-                               (setq pair (cdr pair))))
-                           boundaries)))
+        (line-boundaries
+         (let ((pair popon--line-beginnings)
+               (boundaries nil))
+           (when (eq (car pair) (buffer-modified-tick))
+             (setq pair (cdr pair))
+             (while pair
+               (when (and (integerp (car pair))
+                          (integerp (cadr pair)))
+                 (push (cons (car pair) (cadr pair)) boundaries))
+               (setq pair (cdr pair))))
+           boundaries)))
     (save-excursion
       (goto-char (window-start))
       (let ((mark (point))
@@ -311,8 +320,8 @@ START and END specifies which part to return.  They can be 
in any order."
             (next-invisible
              (if (get-char-property (point) 'invisible)
                  (point)
-               (next-single-char-property-change (point) 'invisible nil
-                                                 (window-end)))))
+               (next-single-char-property-change
+                (point) 'invisible nil (window-end)))))
         (dotimes (i (floor (window-screen-lines)))
           (if-let ((next (alist-get (point) line-boundaries)))
               (goto-char next)
@@ -337,14 +346,18 @@ START and END specifies which part to return.  They can 
be in any order."
             (unless line
               (setq line i)
               (setf (alist-get mark point-to-line) line))
-            (let* ((str (popon--buffer-visible-substring mark (point)))
+            (let* ((str (popon--buffer-visible-substring
+                         mark (point)))
                    (disp-str (if (>= emacs-major-version 26)
                                  (string-trim-right str "\n")
                                (let ((i (string-match-p
-                                         (concat "\\(?:\n\\)\\'") str)))
+                                         (concat "\\(?:\n\\)\\'")
+                                         str)))
                                  (if i (substring str 0 i) str)))))
               (push (list disp-str nil nil line mark
-                          (if (equal str disp-str) (point) (1- (point))))
+                          (if (equal str disp-str)
+                              (point)
+                            (1- (point))))
                     framebuffer)))
           (push (cons mark (point)) line-boundaries)
           (setq mark (point)))))
@@ -398,14 +411,16 @@ START and END specifies which part to return.  They can 
be in any order."
                                    (1- (caar block)) (caar block))
                                   "\n")))
              (setq text "\n"))
-           (dolist (line (sort (cadr (cdr block)) #'car-less-than-car))
+           (dolist (line (sort (cadr (cdr block))
+                               #'car-less-than-car))
              (setq text (concat text
                                 (make-string (- (car line)
                                                 current-offset)
                                              ?\n)
                                 (cdr line)))
              (setq current-offset (car line)))
-           (add-face-text-property 0 (length text) 'default 'append text)
+           (add-face-text-property 0 (length text) 'default 'append
+                                   text)
 
            ;; Pay attention to the `font-lock-face' property.
            (when font-lock-mode
@@ -414,9 +429,10 @@ START and END specifies which part to return.  They can be 
in any order."
                  (let ((next-pos (or (next-single-property-change
                                       pos 'font-lock-face text)
                                      (length text))))
-                   (when-let ((face (get-pos-property pos 'font-lock-face
-                                                      text)))
-                     (add-face-text-property pos next-pos face nil text))
+                   (when-let ((face (get-pos-property
+                                     pos 'font-lock-face text)))
+                     (add-face-text-property pos next-pos face nil
+                                             text))
                    (setq pos next-pos)))))
            text)))
       (when (and (cadr block)
@@ -426,19 +442,22 @@ START and END specifies which part to return.  They can 
be in any order."
                                 (if (facep face)
                                     (when (>= emacs-major-version 27)
                                       (face-attribute face :extend))
-                                  (if-let (val (plist-member face :extend))
+                                  (if-let (val (plist-member
+                                                face :extend))
                                       (cadr val)
                                     'unspecified))))
                              (extend 'unspecified))
-                        (let ((faceprop (get-char-property (cdar block)
-                                                           'face)))
+                        (let ((faceprop (get-char-property
+                                         (cdar block) 'face)))
                           (catch 'done
                             (if (face-list-p faceprop)
                                 (dolist (face faceprop)
-                                  (setq extend (funcall extend-attr face))
+                                  (setq extend (funcall extend-attr
+                                                        face))
                                   (when (booleanp extend)
                                     (throw 'done extend)))
-                              (setq extend (funcall extend-attr faceprop))
+                              (setq extend (funcall extend-attr
+                                                    faceprop))
                               (when (booleanp extend)
                                 (throw 'done extend)))
                             (funcall extend-attr 'default))))))
@@ -476,24 +495,29 @@ When FORCE is non-nil, update all overlays."
                                    (line-number-display-width))
                                0)
                              (if (display-graphic-p)
-                                 (let ((fringes (window-fringes window)))
+                                 (let ((fringes (window-fringes
+                                                 window)))
                                    (/ (+ (car fringes) (cadr fringes))
                                       (frame-char-width frame)))
                                (if (zerop (window-hscroll)) 0 1))))))
-                (copy-sequence (window-parameter window 'popon-list)))))
+                (copy-sequence (window-parameter
+                                window 'popon-list)))))
           (when (or force
                     (not
                      (and
-                      (eq (window-parameter window 'popon-window-start)
+                      (eq (window-parameter
+                           window 'popon-window-start)
                           (window-start window))
-                      (eq (window-parameter window 'popon-window-hscroll)
+                      (eq (window-parameter
+                           window 'popon-window-hscroll)
                           (window-hscroll window))
-                      (eq (window-parameter window 'popon-window-buffer)
+                      (eq (window-parameter
+                           window 'popon-window-buffer)
                           (window-buffer window))
                       (null (cl-set-exclusive-or
                              popons
-                             (window-parameter window
-                                               'popon-visible-popons))))))
+                             (window-parameter
+                              window 'popon-visible-popons))))))
             (while (window-parameter window 'popon-overlays)
               (delete-overlay
                (pop (window-parameter window 'popon-overlays))))
@@ -504,7 +528,8 @@ When FORCE is non-nil, update all overlays."
               (with-selected-window window
                 (let* ((framebuffer (popon--make-framebuffer)))
                   (dolist (popon popons)
-                    (popon--render popon framebuffer (window-hscroll)))
+                    (popon--render popon framebuffer
+                                   (window-hscroll)))
                   (popon--make-overlays framebuffer))))
             (set-window-parameter window 'popon-visible-popons popons)
             (set-window-parameter window 'popon-window-start
@@ -520,7 +545,8 @@ When FORCE is non-nil, update all overlays."
       (remove-hook 'pre-redisplay-functions #'popon--pre-redisplay))
     (if popon-available-p
         (add-hook 'window-configuration-change-hook #'popon-update)
-      (remove-hook 'window-configuration-change-hook #'popon-update))))
+      (remove-hook 'window-configuration-change-hook
+                   #'popon-update))))
 
 ;;;###autoload
 (defun popon-redisplay ()
@@ -538,13 +564,14 @@ When FORCE is non-nil, update all overlays."
 
 ;;;###autoload
 (defun popon-x-y-at-pos (point)
-  "Return the (X, Y) coodinate of POINT in selected window as a cons cell.
+  "Return the (X, Y) coodinate of POINT in selected window as a cons.
 
 Return nil if POINT is not in visible text area.
 
-NOTE: This uses `posn-at-point', which is slow.  So try to minimize calls
-to this function."
-  (let ((window-start-x-y (posn-col-row (posn-at-point (window-start))))
+NOTE: This uses `posn-at-point', which is slow.  So try to minimize
+calls to this function."
+  (let ((window-start-x-y (posn-col-row (posn-at-point
+                                         (window-start))))
         (point-x-y (posn-col-row (posn-at-point point))))
     (cons (if (and (or (not truncate-lines) word-wrap)
                    (if truncate-partial-width-windows



reply via email to

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