Skip to content

Commit

Permalink
Use acm-frame-new macro to remove duplicate code.
Browse files Browse the repository at this point in the history
  • Loading branch information
manateelazycat committed Jun 9, 2023
1 parent 6f714d2 commit ef24aa1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 52 deletions.
15 changes: 15 additions & 0 deletions acm/acm-frame.el
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,21 @@
))
(add-function :after after-focus-change-function #'acm-frame-restore-font))

(cl-defmacro acm-frame-new (frame frame-buffer buffer-name &optional max-width max-height)
`(progn
(when (and (frame-live-p ,frame)
(not (eq (frame-parent ,frame) (selected-frame))))
(acm-frame-delete-frame ,frame))

(acm-frame-create-frame-if-not-exist ,frame ,frame-buffer ,buffer-name 1 t)

(acm-frame-set-frame-max-size ,frame ,max-width ,max-height)

(let ((pos (acm-frame-get-popup-position (point) 1)))
(acm-frame-set-frame-position ,frame (car pos) (cdr pos)))

(acm-frame-adjust-frame-pos ,frame)))

(cl-defmacro acm-frame-create-frame-if-not-exist (frame frame-buffer frame-name margin no-accept-focus)
`(unless (frame-live-p ,frame)
(setq ,frame (acm-frame-make-frame ,frame-name ,no-accept-focus))
Expand Down
19 changes: 3 additions & 16 deletions lsp-bridge-diagnostic.el
Original file line number Diff line number Diff line change
Expand Up @@ -220,22 +220,9 @@ You can set this value with `(2 3 4) if you just need render error diagnostic."
emacs-basic-display
(not (display-graphic-p))))

(when (and (frame-live-p lsp-bridge-diagnostic-frame)
(not (eq (frame-parent lsp-bridge-diagnostic-frame) (selected-frame))))
(acm-frame-delete-frame lsp-bridge-diagnostic-frame))

(acm-frame-create-frame-if-not-exist lsp-bridge-diagnostic-frame
lsp-bridge-diagnostic-buffer
"lsp bridge diagnostic frame"
1
t)

(acm-frame-set-frame-max-size lsp-bridge-diagnostic-frame nil nil)

(let ((pos (acm-frame-get-popup-position (point) 1)))
(acm-frame-set-frame-position lsp-bridge-diagnostic-frame (car pos) (cdr pos)))

(acm-frame-adjust-frame-pos lsp-bridge-diagnostic-frame))
(acm-frame-new lsp-bridge-diagnostic-frame
lsp-bridge-diagnostic-buffer
"lsp bridge diagnostic frame"))
(t (message diagnostic-message)))))

(defun lsp-bridge-diagnostic-maybe-display-error-at-point ()
Expand Down
46 changes: 10 additions & 36 deletions lsp-bridge.el
Original file line number Diff line number Diff line change
Expand Up @@ -1639,24 +1639,11 @@ So we build this macro to restore postion after code format."
(insert value)
(acm-markdown-render-content))

(when (and (frame-live-p lsp-bridge-popup-documentation-frame)
(not (eq (frame-parent lsp-bridge-popup-documentation-frame) (selected-frame))))
(acm-frame-delete-frame lsp-bridge-popup-documentation-frame))

(acm-frame-create-frame-if-not-exist lsp-bridge-popup-documentation-frame
lsp-bridge-popup-documentation-buffer
"lsp bridge popup documentation frame"
1
t)

(acm-frame-set-frame-max-size lsp-bridge-popup-documentation-frame
lsp-bridge-lookup-doc-tooltip-max-width
lsp-bridge-lookup-doc-tooltip-max-height)

(let ((pos (acm-frame-get-popup-position (point) 1)))
(acm-frame-set-frame-position lsp-bridge-popup-documentation-frame (car pos) (cdr pos)))

(acm-frame-adjust-frame-pos lsp-bridge-popup-documentation-frame))
(acm-frame-new lsp-bridge-popup-documentation-frame
lsp-bridge-popup-documentation-buffer
"lsp bridge popup documentation frame"
lsp-bridge-lookup-doc-tooltip-max-width
lsp-bridge-lookup-doc-tooltip-max-height))

(defun lsp-bridge-hide-doc-tooltip ()
(acm-frame-hide-frame lsp-bridge-popup-documentation-frame))
Expand All @@ -1666,7 +1653,7 @@ So we build this macro to restore postion after code format."
:type 'function
:group 'lsp-bridge)

(defcustom lsp-bridge-signature-tooltip " *lsp-bridge-signature*"
(defcustom lsp-bridge-signature-buffer " *lsp-bridge-signature*"
"Buffer for display signature information."
:type 'string
:group 'lsp-bridge)
Expand All @@ -1680,28 +1667,15 @@ So we build this macro to restore postion after code format."
"Use popup frame to show the STR signatureHelp string."
(if (not (string-empty-p str))
(progn
(with-current-buffer (get-buffer-create lsp-bridge-signature-tooltip)
(with-current-buffer (get-buffer-create lsp-bridge-signature-buffer)
(erase-buffer)
(insert str)
(visual-line-mode 1)
(current-buffer))

(when (and (frame-live-p lsp-bridge-signature-frame)
(not (eq (frame-parent lsp-bridge-signature-frame) (selected-frame))))
(acm-frame-delete-frame lsp-bridge-signature-frame))

(acm-frame-create-frame-if-not-exist lsp-bridge-signature-frame
lsp-bridge-signature-tooltip
"lsp bridge signature frame"
1
t)

(acm-frame-set-frame-max-size lsp-bridge-signature-frame nil nil)

(let ((pos (acm-frame-get-popup-position (point) 1)))
(acm-frame-set-frame-position lsp-bridge-signature-frame (car pos) (cdr pos)))

(acm-frame-adjust-frame-pos lsp-bridge-signature-frame))
(acm-frame-new lsp-bridge-signature-frame
lsp-bridge-signature-buffer
"lsp bridge signature frame"))
(lsp-bridge-hide-signature-tooltip)))

(defun lsp-bridge-signature-help--update (help-infos help-index)
Expand Down

0 comments on commit ef24aa1

Please sign in to comment.