forked from AndrewSwerlick/ts-fold
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathts-fold-util.el
90 lines (71 loc) · 2.65 KB
/
ts-fold-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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
;;; ts-fold-util.el --- Utility module -*- lexical-binding: t; -*-
;; Copyright (C) 2021-2023 Shen, Jen-Chieh
;; Created date 2021-10-04 20:19:42
;; This file is NOT part of GNU Emacs.
;; 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 of the License, 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. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;;
;; Utility module.
;;
;;; Code:
;;
;; (@* "Cons" )
;;
(defun ts-fold--cons-add (c1 c2)
"Addition for two cons C1 and C2."
(cons (+ (car c1) (car c2)) (+ (cdr c1) (cdr c2))))
;;
;; (@* "Overlay" )
;;
(defun ts-fold--overlays-in (prop name &optional beg end)
"Return overlays with PROP of NAME, from region BEG to END."
(unless beg (setq beg (point-min))) (unless end (setq end (point-max)))
(let ((lst '()) (ovs (overlays-in beg end)))
(dolist (ov ovs)
(when (eq name (overlay-get ov prop))
(push ov lst)))
lst))
;;
;; (@* "Face" )
;;
(defvar ts-fold--doc-faces
'(font-lock-doc-face
font-lock-comment-face
font-lock-comment-delimiter-face
tree-sitter-hl-face:comment
tree-sitter-hl-face:doc
hl-todo)
"List of face that apply for document string.")
(defun ts-fold--get-face (obj trim)
"Return face name from OBJ.
If argument TRIM is non-nil, trim the OBJ."
(get-text-property 0 'face (if trim (string-trim obj) obj)))
(defun ts-fold--is-face (obj lst-face &optional trim)
"Return non-nil if OBJ's face is define inside list LST-FACE.
Optional argument TRIM, see function `ts-fold--get-face'."
(unless (listp lst-face) (setq lst-face (list lst-face)))
(let ((faces (ts-fold--get-face obj trim)))
(cond ((listp faces)
(cl-some (lambda (face) (memq face lst-face)) faces))
(t (memq faces lst-face)))))
(defun ts-fold--doc-faces-p (obj &optional trim)
"Return non-nil if face at OBJ is within `ts-fold--doc-faces' list.
Optional argument TRIM, see function `ts-fold--get-face'."
(ts-fold--is-face obj ts-fold--doc-faces trim))
;;
;; (@* "Math" )
;;
(defun ts-fold--in-range-p (in-val in-min in-max)
"Check to see if IN-VAL is between IN-MIN and IN-MAX."
(and (<= in-min in-val) (<= in-val in-max)))
(provide 'ts-fold-util)
;;; ts-fold-util.el ends here