acm-terminal: 终端也可以用上 lsp-bridge

我是在这个网站上直接复制字体图标https://www.nerdfonts.com/font-downloads, (defun switch-acm-icon (value) (cond ((equal value “Function”) " 󰡱 ") ((equal value “Keyword”) "  ") ((equal value “Moudle”) "  ") ((equal value “Method”) "  ") ((equal value “Snippet”) " 󰡱 ") ((equal value “Text”) " 󰊄 ") ((equal value “Variable”) " 󱀍 ") ((equal value “Class”) "  ") (t " 󰮂 ")))

安装了大佬的这个插件,贼好用

今天弄了以下nerd font的菜单图标,增加了一个 acm-terminal-enable-annotation-icon 自定义,默认为nil, 配置为t时,在菜单前面显示nerd font的图标,后面的annotation就不显示了。

java

go emacs-lisp

From 69831620eb9599dc52d796c1378764ec57c650c0 Mon Sep 17 00:00:00 2001
From: Zhou Peng <[email protected]>
Date: Wed, 31 Jan 2024 15:17:29 +0800
Subject: [PATCH] Add annotation icon for popup completion.

Install nerd fonts before enable acm-terminal annotation icon.
To enable annotation icon(s), customize
`acm-terminal-enable-annotation-icon` to `t`.

(use-package acm-terminal
  :custom
  (acm-terminal-enable-annotation-icon t)

---
 acm-terminal.el | 55 ++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 43 insertions(+), 12 deletions(-)

diff --git a/acm-terminal.el b/acm-terminal.el
index d03f523..c86a8b4 100644
--- a/acm-terminal.el
+++ b/acm-terminal.el
@@ -73,6 +73,29 @@
 (defvar acm-terminal-doc-max-width 80
   "The maximum width of the candidate doc in characters.")
 
+(defvar acm-terminal-annotation-icons
+  '(("Function" . " 󰡱 ")
+    ("Keyword" . "  ")
+    ("Module" . "  ")
+    ("Method" . "  ")
+    ("Struct" . "  ")
+    ("Snippet" . "  ")
+    ("Text" . "  ")
+    ("Variable" . " 󰫧 ")
+    ("Class" . "  ")
+    ("Custom" . "  ")
+    ("Feature" . " 󰯺 ")
+    ("Macro" . " 󰰏 ")
+    ("Interface" . "  ")
+    ("Constant" . "  ")
+    ("Field" . "  "))
+  "Annotation icons.")
+
+(defcustom acm-terminal-enable-annotation-icon nil
+  "Enable annotation icon display instead of text, default false."
+  :type 'boolean
+  :group 'acm-terminal)
+
 (defvar-local acm-terminal-candidate-doc nil
   "Latest docstring.")
 
@@ -193,6 +216,10 @@ See `popon-create' for more information."
           (+ (- (car (window-inside-edges)) (window-left-column))
              (acm-terminal-line-number-display-width)))))
 
+(defun acm-terminal-menu-item-icon-text (annotation)
+  "Returns icon text for given annotation."
+  (cdr (assoc annotation acm-terminal-annotation-icons)))
+
 (defun acm-terminal-menu-render-items (items menu-index)
   (let* ((item-index 0)
          ;; The max length is calcuated base on the format
@@ -207,18 +234,15 @@ See `popon-create' for more information."
          ;;
          ;; without changing the format, then we should add 1 when using
          ;; `acm-menu-max-length-cache'.
-         (max-length (1- acm-menu-max-length-cache))
-         (annotation-not-exits (cl-every (lambda (item) (string-empty-p (plist-get item :annotation))) items)))
+         (max-length (1- acm-menu-max-length-cache)))
     (dolist (v items)
-      (let* ((icon (cdr (assoc (downcase (plist-get v :icon)) acm-icon-alist)))
-             (candidate (plist-get v :displayLabel))
+      (let* ((candidate (plist-get v :displayLabel))
              (candidate-length (funcall acm-string-width-function candidate))
              (annotation (plist-get v :annotation))
              (annotation-text (if annotation annotation ""))
-             (annotation-length (funcall acm-string-width-function annotation-text))
+             (annotation-length (if acm-terminal-enable-annotation-icon 0 (funcall acm-string-width-function annotation-text)))
              (candidate-max-length (- max-length annotation-length 2))
-             (padding-length (- max-length (+ candidate-length annotation-length) 2))
-             (icon-text (if icon (acm-icon-build (nth 0 icon) (nth 1 icon) (nth 2 icon)) ""))
+             (padding-length (if acm-terminal-enable-annotation-icon (- max-length candidate-length 8) (- max-length (+ candidate-length annotation-length) 2)))
              (quick-access-key (nth item-index acm-quick-access-keys))
              candidate-line)
 
@@ -229,7 +253,10 @@ See `popon-create' for more information."
         ;; Build candidate line.
         (setq candidate-line
               (concat
-               ;; icon-text
+               (when acm-terminal-enable-annotation-icon
+                 (propertize (format "%s" (acm-terminal-menu-item-icon-text annotation))
+                             'face
+                             (if (equal item-index menu-index) 'acm-terminal-select-face 'font-lock-doc-face)))
                (when acm-enable-quick-access
                  (if quick-access-key (concat quick-access-key ". ") "   "))
                (if (zerop padding-length)
@@ -238,10 +265,14 @@ See `popon-create' for more information."
                      (concat candidate (make-string padding-length ?\s))
                    (truncate-string-to-width candidate candidate-max-length
                                              0 ?\s)))
-               " "
-               (propertize (format "%s \n" (capitalize annotation-text))
-                           'face
-                           (if (equal item-index menu-index) 'acm-terminal-select-face 'font-lock-doc-face))))
+              (if acm-terminal-enable-annotation-icon
+                  "\n"
+                " ")
+
+              (unless acm-terminal-enable-annotation-icon
+                (propertize (format "%s \n" (capitalize annotation-text))
+                            'face
+                            (if (equal item-index menu-index) 'acm-terminal-select-face 'font-lock-doc-face)))))
 
         ;; Render current candidate.
         (if (equal item-index menu-index)
-- 
2.43.0