forked from purcell/call-graph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cg-lib.el
83 lines (65 loc) · 2.68 KB
/
cg-lib.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
;;; cg-lib.el --- call-graph routines. -*- lexical-binding: t -*-
;; Copyright (C) 2019-2021 Huming Chen
;; Author: Huming Chen <chenhuming@gmail.com>
;; Maintainer: Huming Chen <chenhuming@gmail.com>
;; URL: https://github.com/beacoder/call-graph
;; Version: 0.1.0
;; Keywords: programming, convenience
;; Created: 2018-01-07
;; Package-Requires: ((emacs "25.1"))
;; 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 <http://www.gnu.org/licenses/>.
;;; Commentary:
;; All functions that don't require specific call-graph code should go here.
;;; Code:
(require 'cl-lib)
(require 'which-func)
(require 'seq)
(require 'map)
(require 'subr-x)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Helpers
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; steal from ag/dwim-at-point
(defun cg--dwim-at-point ()
"If there's an active selection, return that.
Otherwise, get the symbol at point, as a string."
(cond ((use-region-p)
(buffer-substring-no-properties (region-beginning) (region-end)))
((symbol-at-point)
(substring-no-properties
(symbol-name (symbol-at-point))))))
;;; improved version, based on ag/read-from-minibuffer
(defun cg--read-from-minibuffer (prompt)
"Read a value from the minibuffer with PROMPT.
If there's a string at point, use it instead of prompt."
(let* ((suggested (cg--dwim-at-point))
(final-prompt
(if suggested (format "%s (default %s): " prompt suggested)
(format "%s: " prompt))))
(if (or current-prefix-arg (string= "" suggested) (not suggested))
(read-from-minibuffer final-prompt nil nil nil nil suggested)
suggested)))
;;; borrowed from somewhere else
(defun cg--trim-string (string)
"Remove white spaces in beginning and ending of STRING.
White space here is any of: space, tab, Emacs newline (line feed, ASCII 10)."
(replace-regexp-in-string
"\\`[ \t\n]*" ""
(replace-regexp-in-string
"[ \t\n]*\\'" "" string)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Tests
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; @see cg-test.el
(provide 'cg-lib)
;;; cg-lib.el ends here