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

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

[nongnu] elpa/telephone-line 835179cc9b 060/195: Put segment stuff back


From: ELPA Syncer
Subject: [nongnu] elpa/telephone-line 835179cc9b 060/195: Put segment stuff back in the correct place, further refactor for the new separators
Date: Wed, 5 Jan 2022 02:59:26 -0500 (EST)

branch: elpa/telephone-line
commit 835179cc9b6693aad93d3e0044abf395e49f1de5
Author: Daniel Bordak <dbordak@fastmail.fm>
Commit: Daniel Bordak <dbordak@fastmail.fm>

    Put segment stuff back in the correct place, further refactor for the new 
separators
---
 telephone-line-utils.el | 121 +++++++++++++++++++++++++-----------------------
 1 file changed, 62 insertions(+), 59 deletions(-)

diff --git a/telephone-line-utils.el b/telephone-line-utils.el
index ba1e92d000..473f472f49 100644
--- a/telephone-line-utils.el
+++ b/telephone-line-utils.el
@@ -137,56 +137,6 @@ color1 and color2."
   `(lambda (x)
      (- (,func x))))
 
-(defun telephone-line--separator-arg-handler (arg)
-  "Translate ARG into an appropriate color for a separator."
-  (if (facep arg)
-      (face-attribute arg :background)
-    arg))
-
-(defun telephone-line--pad-body (body char-width)
-  "Pad 2d byte-list BODY to a width of CHAR-WIDTH, given as a number of 
characters."
-  (let* ((body-width (length (car body)))
-         (padding-width (- (* char-width (frame-char-width)) body-width))
-         (left-padding (make-list (floor padding-width 2) 1))
-         (right-padding (make-list (ceiling padding-width 2) 1)))
-    (mapcar (lambda (row)
-              (append left-padding row right-padding))
-            body)))
-
-:autoload
-(defmacro telephone-line-defsegment (name body)
-  "Create function NAME by wrapping BODY with telephone-line padding and 
propertization."
-  (declare (indent defun))
-  `(defun ,name (face)
-     (telephone-line-raw ,body face)))
-
-:autoload
-(defmacro telephone-line-defsegment* (name body)
-  "Create function NAME by wrapping BODY with telephone-line padding and 
propertization.
-Segment is not precompiled."
-  (declare (indent defun))
-  `(defun ,name (face)
-     (telephone-line-raw ,body)))
-
-:autoload
-(defmacro telephone-line-defsegment-plist (name plists)
-  (declare (indent defun))
-  `(defun ,name (face)
-     (telephone-line-raw
-      (mapcar (lambda (plist)
-                (plist-put plist 'face face))
-              ,plists))))
-
-:autoload
-(defun telephone-line-raw (str &optional compiled)
-  "Conditionally render STR as mode-line data, or just verify output if not 
COMPILED.
-Return nil for blank/empty strings."
-  (let ((trimmed-str (s-trim (format-mode-line str))))
-    (unless (s-blank? trimmed-str)
-      (if compiled
-          (replace-regexp-in-string "%" "%%" trimmed-str)
-        str))))
-
 (defclass telephone-line-separator ()
   ((axis-func :initarg :axis-func)
    (pattern-func :initarg :pattern-func :initform #'telephone-line-row-pattern)
@@ -216,33 +166,86 @@ Return nil for blank/empty strings."
                        (* x scaling-factor) width))
             normalized-axis)))
 
+(defun telephone-line--pad-body (body char-width)
+  "Pad 2d byte-list BODY to a width of CHAR-WIDTH, given as a number of 
characters."
+  (let* ((body-width (length (car body)))
+         (padding-width (- (* char-width (frame-char-width)) body-width))
+         (left-padding (make-list (floor padding-width 2) 1))
+         (right-padding (make-list (ceiling padding-width 2) 1)))
+    (mapcar (lambda (row)
+              (append left-padding row right-padding))
+            body)))
+
 (defmethod telephone-line-separator-create-body ((obj 
telephone-line-subseparator))
   (telephone-line--pad-body (call-next-method)
               (+ (ceiling (telephone-line-separator-width obj)
                           (frame-char-width))
                  telephone-line-separator-extra-padding)))
 
+(defmethod telephone-line-separator--arg-handler (arg) :static
+  "Translate ARG into an appropriate color for a separator."
+  (if (facep arg)
+      (face-attribute arg :background)
+    arg))
+
 (defmethod telephone-line-separator-render ((obj telephone-line-separator) 
foreground background)
-  (let* ((bg-color (telephone-line--separator-arg-handler background))
-         (fg-color (telephone-line--separator-arg-handler foreground))
-         (hash-key (concat bg-color "_" fg-color)))
-    (if window-system
+  (telephone-line-separator--render obj
+                      (telephone-line-separator--arg-handler foreground)
+                      (telephone-line-separator--arg-handler background)))
+
+(defmethod telephone-line-separator--render ((obj telephone-line-separator) 
foreground background)
+  (if window-system
+      (let ((hash-key (concat background "_" foreground)))
         ;; Return cached image if we have it.
         (or (gethash hash-key (oref obj image-cache))
             (puthash hash-key
                      (telephone-line-propertize-image
                       (telephone-line--create-pbm-image 
(telephone-line-separator-create-body obj)
-                                          bg-color fg-color))
-                     (oref obj image-cache)))
+                                          background foreground))
+                     (oref obj image-cache))))
 
       (list :propertize (char-to-string (oref obj alt-char))
-            'face (list :foreground fg-color
-                        :background bg-color
-                        :inverse-video t)))))
+            'face (list :foreground foreground
+                        :background background
+                        :inverse-video t))))
 
 (defmethod telephone-line-separator-clear-cache ((obj 
telephone-line-separator))
   (clrhash (oref obj image-cache)))
 
+:autoload
+(defmacro telephone-line-defsegment (name body)
+  "Create function NAME by wrapping BODY with telephone-line padding and 
propertization."
+  (declare (indent defun))
+  `(defun ,name (face)
+     (telephone-line-raw ,body face)))
+
+:autoload
+(defmacro telephone-line-defsegment* (name body)
+  "Create function NAME by wrapping BODY with telephone-line padding and 
propertization.
+Segment is not precompiled."
+  (declare (indent defun))
+  `(defun ,name (face)
+     (telephone-line-raw ,body)))
+
+:autoload
+(defmacro telephone-line-defsegment-plist (name plists)
+  (declare (indent defun))
+  `(defun ,name (face)
+     (telephone-line-raw
+      (mapcar (lambda (plist)
+                (plist-put plist 'face face))
+              ,plists))))
+
+:autoload
+(defun telephone-line-raw (str &optional compiled)
+  "Conditionally render STR as mode-line data, or just verify output if not 
COMPILED.
+Return nil for blank/empty strings."
+  (let ((trimmed-str (s-trim (format-mode-line str))))
+    (unless (s-blank? trimmed-str)
+      (if compiled
+          (replace-regexp-in-string "%" "%%" trimmed-str)
+        str))))
+
 ;;Stole this bit from seq.el
 (defun telephone-line--activate-font-lock-keywords ()
   "Activate font-lock keywords for some symbols defined in telephone-line."



reply via email to

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