[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/eglot e63dad0 092/139: Simplify mode-line code with a h
From: |
João Távora |
Subject: |
[elpa] externals/eglot e63dad0 092/139: Simplify mode-line code with a helper. |
Date: |
Mon, 14 May 2018 09:55:00 -0400 (EDT) |
branch: externals/eglot
commit e63dad0bc5ae5f1233907e1ae3c1dbd7c2a02d81
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>
Simplify mode-line code with a helper.
* eglot.el (eglot--mdoe-line-props): New helper.
(eglot--mode-line-format): Use it.
---
eglot.el | 118 ++++++++++++++++++++-------------------------------------------
1 file changed, 38 insertions(+), 80 deletions(-)
diff --git a/eglot.el b/eglot.el
index a600f47..02439df 100644
--- a/eglot.el
+++ b/eglot.el
@@ -817,93 +817,51 @@ that case, also signal textDocument/didOpen."
(with-selected-window (posn-window (event-start event))
(call-interactively what))))
+(defun eglot--mode-line-props (thing face defs &optional prepend)
+ "Helper for function `eglot--mode-line-format'.
+Uses THING, FACE, DEFS and PREPEND."
+ (cl-loop with map = (make-sparse-keymap)
+ for (elem . rest) on defs
+ for (key def help) = elem
+ do (define-key map `[mode-line ,key] (eglot--mode-line-call def))
+ concat (format "%s: %s" key help) into blurb
+ when rest concat "\n" into blurb
+ finally (return `(:propertize ,thing
+ face ,face
+ keymap ,map help-echo ,(concat
prepend blurb)
+ mouse-face mode-line-highlight))))
+
(defun eglot--mode-line-format ()
- "Compose the mode-line format spec."
+ "Compose the EGLOT's mode-line."
(pcase-let* ((proc (eglot--current-process))
- (name (and proc
- (process-live-p proc)
- (eglot--short-name proc)))
- (pending (and proc
- (hash-table-count
- (eglot--pending-continuations proc))))
- (`(,_id ,doing ,done-p)
- (and proc
- (eglot--spinner proc)))
- (`(,status ,serious-p)
- (and proc
- (eglot--status proc))))
+ (name (and (process-live-p proc) (eglot--short-name proc)))
+ (pending (and proc (hash-table-count
+ (eglot--pending-continuations proc))))
+ (`(,_id ,doing ,done-p) (and proc (eglot--spinner proc)))
+ (`(,status ,serious-p) (and proc (eglot--status proc))))
(append
- `((:propertize "eglot"
- face eglot-mode-line
- keymap ,(let ((map (make-sparse-keymap)))
- (define-key map [mode-line down-mouse-1]
- (eglot--mode-line-call 'eglot-menu))
- map)
- mouse-face mode-line-highlight
- help-echo "mouse-1: pop-up EGLOT menu"
- ))
+ `(,(eglot--mode-line-props "eglot" 'eglot-mode-line
+ '((down-mouse-1 eglot-menu "pop up EGLOT
menu"))))
(when name
- `(":"
- (:propertize
- ,name
- face eglot-mode-line
- keymap ,(let ((map (make-sparse-keymap)))
- (define-key map [mode-line mouse-1]
- (eglot--mode-line-call 'eglot-events-buffer))
- (define-key map [mode-line mouse-2]
- (eglot--mode-line-call 'eglot-shutdown))
- (define-key map [mode-line mouse-3]
- (eglot--mode-line-call 'eglot-reconnect))
- map)
- mouse-face mode-line-highlight
- help-echo ,(concat "mouse-1: go to events buffer\n"
- "mouse-2: quit server\n"
- "mouse-3: reconnect to server"))
+ `(":" ,(eglot--mode-line-props
+ name 'eglot-mode-line
+ '((mouse-1 eglot-events-buffer "go to events buffer")
+ (mouse-2 eglot-shutdown "quit server")
+ (mouse-3 eglot-reconnect "reconnect to server")))
,@(when serious-p
- `("/"
- (:propertize
- ,status
- help-echo ,(concat "mouse-1: go to events buffer\n"
- "mouse-3: clear this status")
- mouse-face mode-line-highlight
- face compilation-mode-line-fail
- keymap ,(let ((map (make-sparse-keymap)))
- (define-key map [mode-line mouse-1]
- (eglot--mode-line-call 'eglot-events-buffer))
- (define-key map [mode-line mouse-3]
- (eglot--mode-line-call 'eglot-clear-status))
- map))))
+ `("/" ,(eglot--mode-line-props
+ status 'compilation-mode-line-fail
+ '((mouse-1 eglot-events-buffer "go to events buffer")
+ (mouse-3 eglot-clear-status "clear this status")))))
,@(when (and doing (not done-p))
- `("/"
- (:propertize
- ,doing
- help-echo ,(concat "mouse-1: go to events buffer")
- mouse-face mode-line-highlight
- face compilation-mode-line-run
- keymap ,(let ((map (make-sparse-keymap)))
- (define-key map [mode-line mouse-1]
- (eglot--mode-line-call 'eglot-events-buffer))
- map))))
+ `("/" ,(eglot--mode-line-props
+ doing 'compilation-mode-line-run
+ '((mouse-1 eglot-events-buffer "go to events buffer")))))
,@(when (cl-plusp pending)
- `("/"
- (:propertize
- (format "%d" pending)
- help-echo ,(format
- "%s unanswered requests\n%s"
- pending
- (concat "mouse-1: go to events buffer"
- "mouse-3: forget pending continuations"))
- mouse-face mode-line-highlight
- face ,(cond ((and pending (cl-plusp pending))
- 'warning)
- (t
- 'eglot-mode-line))
- keymap ,(let ((map (make-sparse-keymap)))
- (define-key map [mode-line mouse-1]
- (eglot--mode-line-call 'eglot-events-buffer))
- (define-key map [mode-line mouse-3]
- (eglot--mode-line-call
'eglot-forget-pending-continuations))
- map)))))))))
+ `("/" ,(eglot--mode-line-props
+ (format "%d" pending) 'warning
+ '((mouse-1 eglot-events-buffer "go to events buffer")
+ (mouse-3 eglot-clear-status "clear this
status"))))))))))
(add-to-list 'mode-line-misc-info `(eglot-mode (" [" eglot--mode-line-format
"] ")))
- [elpa] externals/eglot d33a9b5 103/139: Simplify eglot--signal-textDocument/didChange, (continued)
- [elpa] externals/eglot d33a9b5 103/139: Simplify eglot--signal-textDocument/didChange, João Távora, 2018/05/14
- [elpa] externals/eglot ef80455 121/139: Support :completionItem/resolve, João Távora, 2018/05/14
- [elpa] externals/eglot f89f859 114/139: Simplify mode-line updating logic, João Távora, 2018/05/14
- [elpa] externals/eglot 3a6c637 099/139: Support textDocument/rename, João Távora, 2018/05/14
- [elpa] externals/eglot 581608f 115/139: Resist server failure during synchronous requests, João Távora, 2018/05/14
- [elpa] externals/eglot 56cf02d 126/139: Rework autoreconnection logic, João Távora, 2018/05/14
- [elpa] externals/eglot 4c0bfc3 139/139: Support didChangeWatchedFiles with dynamic registration, João Távora, 2018/05/14
- [elpa] externals/eglot 42177d0 107/139: New "deferred requests" that wait until server is ready, João Távora, 2018/05/14
- [elpa] externals/eglot 29f6b4c 129/139: Tweak README.md, João Távora, 2018/05/14
- [elpa] externals/eglot 1fb2bcb 132/139: Ask server for textDocument/signatureHelp if it supports it, João Távora, 2018/05/14
- [elpa] externals/eglot e63dad0 092/139: Simplify mode-line code with a helper.,
João Távora <=
- [elpa] externals/eglot ab575d2 120/139: Rename functions. eglot--request is now the synchronous one, João Távora, 2018/05/14
- [elpa] externals/eglot 41f5922 137/139: Now send willSaveWaitUntil, João Távora, 2018/05/14
- [elpa] externals/eglot 458bc69 110/139: More correctly setup rust-mode-related autoloads, João Távora, 2018/05/14
- [elpa] externals/eglot 9af84a2 124/139: Prepare to sumbit to GNU ELPA, João Távora, 2018/05/14
- [elpa] externals/eglot 0625b6c 123/139: (eglot--xref-make): Fix Use of cl-destructuring-bind., João Távora, 2018/05/14
- [elpa] externals/eglot 589e1ea 138/139: Remove an unused variable, João Távora, 2018/05/14
- [elpa] externals/eglot 49fb02f 135/139: Use RLS in Travis CI and add actual tests, João Távora, 2018/05/14
- [elpa] externals/eglot dc08e8e 134/139: Fix automatic project creation, João Távora, 2018/05/14
- [elpa] externals/eglot e964abe 091/139: Get rid of eglot--buffer-open-count, João Távora, 2018/05/14
- [elpa] externals/eglot c7b9002 116/139: Only call deferred actions after a full message has been received, João Távora, 2018/05/14