-
Notifications
You must be signed in to change notification settings - Fork 142
/
lsp-ui-util.el
66 lines (51 loc) · 2.22 KB
/
lsp-ui-util.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
;;; lsp-ui-util.el --- Utility module for Lsp-Ui -*- lexical-binding: t -*-
;; Copyright (C) 2020-2024 Shen, Jen-Chieh
;;; License
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
;; Floor, Boston, MA 02110-1301, USA.
;;; Commentary:
;;
;; Utility module for Lsp-Ui.
;;
;;; Code:
(require 'face-remap)
(defun lsp-ui-util-safe-kill-timer (timer)
"Safely kill the TIMER."
(when (timerp timer) (cancel-timer timer)))
(defun lsp-ui-util-safe-delete-overlay (overlay)
"Safely delete the OVERLAY."
(when (overlayp overlay) (delete-overlay overlay)))
(defun lsp-ui-util-line-number-display-width ()
"Safe way to get value from function `line-number-display-width'."
(if (bound-and-true-p display-line-numbers-mode)
;; For some reason, function `line-number-display-width' gave
;; us error `args-out-of-range' even we do not pass anything towards
;; to it function. See the following links,
;;
;; - https://github.com/emacs-lsp/lsp-ui/issues/294
;; - https://github.com/emacs-lsp/lsp-ui/issues/533 (duplicate)
(+ (or (ignore-errors (line-number-display-width)) 0) 2)
0))
(defun lsp-ui-util-line-string (pos)
"Return string at POS."
(when (integerp pos) (save-excursion (goto-char pos) (thing-at-point 'line))))
(defun lsp-ui-util-column (&optional pos)
"Return column at POS."
(setq pos (or pos (point)))
(save-excursion (goto-char pos) (current-column)))
(defun lsp-ui-util-text-scale-factor ()
"Return the factor effect by `text-scale-mode'."
(or (plist-get (cdr text-scale-mode-remapping) :height) 1))
(provide 'lsp-ui-util)
;;; lsp-ui-util.el ends here