branch: elpa/gnosis
commit 5a66ab4cca63729290e5086219dcac4e70950b7b
Author: Thanos Apollo <pub...@thanosapollo.org>
Commit: Thanos Apollo <pub...@thanosapollo.org>

    center-string: Adjust for links.
    
    + Keep only the desc of links.
---
 gnosis.el | 29 ++++++++++++++++++-----------
 1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/gnosis.el b/gnosis.el
index 026adf910a..ffa810fc9d 100644
--- a/gnosis.el
+++ b/gnosis.el
@@ -321,21 +321,28 @@ Acts only when CENTER? is non-nil."
       (insert text))))
 
 (defun gnosis-center-string (string)
-  "Center each line of STRING in current window width."
+  "Center each line of STRING in current window width.
+
+Removes source from links, returns only link descriptions."
   (let ((width (window-width)))
     (mapconcat
      (lambda (line)
        (let ((trimmed (string-trim line)))
-         (mapconcat
-          (lambda (wrapped)
-            (concat (make-string (max 0 (/ (- width (length wrapped)) 2)) ?\s)
-                    wrapped))
-          (split-string (with-temp-buffer
-                         (insert trimmed)
-                         (fill-region (point-min) (point-max))
-                         (buffer-string))
-                       "\n")
-          "\n")))
+         (let ((adjusted-line
+                (replace-regexp-in-string 
+                 "\\[\\[\\([^]]+\\)\\]\\[\\([^]]+\\)\\]\\]"
+                 "\\2"  ; Keep only description part
+                 trimmed)))
+           (mapconcat
+            (lambda (wrapped)
+              (concat (make-string (max 0 (/ (- width (length wrapped)) 2)) 
?\s)
+                      wrapped))
+            (split-string (with-temp-buffer
+                          (insert adjusted-line)
+                          (fill-region (point-min) (point-max))
+                          (buffer-string))
+                        "\n")
+            "\n"))))
      (split-string string "\n")
      "\n")))
 

Reply via email to