branch: externals/ellama
commit b8e7468f1cdd7d8fbdf31729f6cf239a77ed8fa6
Author: Sergey Kostyaev <sskosty...@gmail.com>
Commit: Sergey Kostyaev <sskosty...@gmail.com>

    Refactor session line update functions
    
    Refactored ellama.el to remove redundant show and hide functions for header 
and
    mode lines. Simplified the update functions by using a let-bound element
    variable and conditionally adding or removing it from the respective line 
format
    lists.
---
 ellama.el | 34 ++++++++++------------------------
 1 file changed, 10 insertions(+), 24 deletions(-)

diff --git a/ellama.el b/ellama.el
index 2699d7bc04..9b50ed8c22 100644
--- a/ellama.el
+++ b/ellama.el
@@ -671,20 +671,13 @@ This filter contains only subset of markdown syntax to be 
good enough."
                        ellama--current-session-id))
              'face 'ellama-face))
 
-(defun ellama-session-show-header-line ()
-  "Display session id in the header line."
-  (when (listp header-line-format)
-    (add-to-list 'header-line-format '(:eval (ellama-session-line)) t)))
-
-(defun ellama-session-hide-header-line ()
-  "Hide session id from header line."
-  (setq header-line-format (delete '(:eval (ellama-session-line)) 
header-line-format)))
-
 (defun ellama-session-update-header-line ()
   "Update header line for ellama session header line mode."
-  (if ellama-session-header-line-mode
-      (ellama-session-show-header-line)
-    (ellama-session-hide-header-line)))
+  (when (listp header-line-format)
+    (let ((element '(:eval (ellama-session-line))))
+      (if ellama-session-header-line-mode
+          (add-to-list 'header-line-format element t)
+       (setq header-line-format (delete element header-line-format))))))
 
 ;;;###autoload
 (define-minor-mode ellama-session-header-line-mode
@@ -697,20 +690,13 @@ This filter contains only subset of markdown syntax to be 
good enough."
   ellama-session-header-line-mode
   ellama-session-header-line-mode)
 
-(defun ellama-session-show-mode-line ()
-  "Display session id in the mode line."
-  (when (listp mode-line-format)
-    (add-to-list 'mode-line-format '(:eval (ellama-session-line)) t)))
-
-(defun ellama-session-hide-mode-line ()
-  "Hide session id from mode line."
-  (setq mode-line-format (delete '(:eval (ellama-session-line)) 
mode-line-format)))
-
 (defun ellama-session-update-mode-line ()
   "Update mode line for ellama session mode line mode."
-  (if ellama-session-mode-line-mode
-      (ellama-session-show-mode-line)
-    (ellama-session-hide-mode-line)))
+  (when (listp mode-line-format)
+    (let ((element '(:eval (ellama-session-line))))
+      (if ellama-session-mode-line-mode
+         (add-to-list 'mode-line-format element t)
+       (setq mode-line-format (delete element mode-line-format))))))
 
 ;;;###autoload
 (define-minor-mode ellama-session-mode-line-mode

Reply via email to