forked from clojure-emacs/cider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cider-util.el
88 lines (69 loc) · 2.89 KB
/
cider-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
;;; cider-util.el --- Common utility functions that don't belong anywhere else -*- lexical-binding: t -*-
;; Copyright © 2012-2014 Tim King, Phil Hagelberg
;; Copyright © 2013-2014 Bozhidar Batsov, Hugo Duncan, Steve Purcell
;;
;; Author: Tim King <[email protected]>
;; Phil Hagelberg <[email protected]>
;; Bozhidar Batsov <[email protected]>
;; Hugo Duncan <[email protected]>
;; Steve Purcell <[email protected]>
;; 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/>.
;; This file is not part of GNU Emacs.
;;; Commentary:
;; Common utility functions that don't belong anywhere else
;;; Code:
(require 'dash)
;;; Compatibility
(eval-and-compile
;; `setq-local' for Emacs 24.2 and below
(unless (fboundp 'defvar-local)
(defmacro defvar-local (var val &optional docstring)
"Define VAR as a buffer-local variable with default value VAL.
Like `defvar' but additionally marks the variable as being automatically
buffer-local wherever it is set."
(declare (debug defvar) (doc-string 3))
`(progn
(defvar ,var ,val ,docstring)
(make-variable-buffer-local ',var))))
;; `setq-local' for Emacs 24.2 and below
(unless (fboundp 'setq-local)
(defmacro setq-local (var val)
"Set variable VAR to value VAL in current buffer."
`(set (make-local-variable ',var) ,val))))
(defun cider-util--hash-keys (hashtable)
"Return a list of keys in HASHTABLE."
(let ((keys '()))
(maphash (lambda (k _v) (setq keys (cons k keys))) hashtable)
keys))
(defun cider-util--clojure-buffers ()
"Return a list of all existing `clojure-mode' buffers."
(-filter
(lambda (buffer) (with-current-buffer buffer (derived-mode-p 'clojure-mode)))
(buffer-list)))
(defun cider-font-lock-as-clojure (string)
"Font-lock STRING as Clojure code."
(with-temp-buffer
(insert string)
(clojure-mode)
(font-lock-fontify-buffer)
(buffer-string)))
(defun cider-format-pprint-eval (form)
"Return a string of Clojure code that will eval and pretty-print FORM."
(format "(let [x %s] (clojure.pprint/pprint x) x)" form))
(autoload 'pkg-info-version-info "pkg-info.el")
(defun cider--version ()
"Retrieve CIDER's version."
(condition-case nil
(pkg-info-version-info 'cider)
(error cider-version)))
(provide 'cider-util)
;;; cider-util.el ends here