Skip to content

Commit b872721

Browse files
committed
Add inf-clojure-meta
#### Summary This commit addresses clojure-emacs#57 (Add an interactive command to display a var's metadata) by adding a command to show forms metadata: `inf-clojure-meta`. `inf-clojure-meta` can be called interactively sends the current form to the inf clojure process and evaluates its metadata. It is useful for testing. This command should work with clojure (through lein repl), lumo and planck alike. #### Test Plan Manually tested the command using clojure, lumo and planck. I put my cursor on a form and ran it interactively, it displayed the metadata in the inf buffer.
1 parent 59868ff commit b872721

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## master (unreleased)
44

55
* [#135](https://github.com/clojure-emacs/inf-clojure/pull/135): Improve command sanitation code.
6+
* [#157](https://github.com/clojure-emacs/inf-clojure/pull/157): Add `inf-clojure-meta`
67

78
## 2.1.0 (2018-01-02)
89

inf-clojure.el

+42
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,39 @@ If you are using REPL types, it will pickup the most approapriate
10991099

11001100
(define-obsolete-variable-alias 'inf-clojure-macroexpand-1-command 'inf-clojure-macroexpand-1-form "2.0.0")
11011101

1102+
;;; Metadata
1103+
;;; ===================
1104+
(defcustom inf-clojure-meta-format
1105+
"(clojure.core/meta %s)"
1106+
"Form to retrieve metadata of another form."
1107+
:type 'string
1108+
:safe #'stringp
1109+
:package-version '(inf-clojure . "2.2.0"))
1110+
1111+
(defcustom inf-clojure-meta-format-planck
1112+
"(meta %s)"
1113+
"Planck form to retrieve metadata of another form."
1114+
:type 'string
1115+
:safe #'stringp
1116+
:package-version '(inf-clojure . "2.2.0"))
1117+
1118+
(defcustom inf-clojure-meta-format-lumo
1119+
"(meta %s)"
1120+
"Lumo form to retrieve metadata of another form."
1121+
:type 'string
1122+
:safe #'stringp
1123+
:package-version '(inf-clojure . "2.2.0"))
1124+
1125+
(defun inf-clojure-meta-form (proc)
1126+
"Return the form for retrieving metadata in the Inf-Clojure PROC.
1127+
If you are using REPL types, it will pickup the most appropriate
1128+
`inf-clojure-meta-format` variant."
1129+
(inf-clojure--sanitize-command
1130+
(pcase (inf-clojure--set-repl-type proc)
1131+
(`lumo inf-clojure-meta-format-lumo)
1132+
(`planck inf-clojure-meta-format-planck)
1133+
(_ inf-clojure-meta-format))))
1134+
11021135
;;; Ancillary functions
11031136
;;; ===================
11041137

@@ -1345,6 +1378,15 @@ thing. See variable `inf-clojure-apropos-form'."
13451378
(let ((proc (inf-clojure-proc)))
13461379
(inf-clojure--send-string proc (format (inf-clojure-apropos-form proc) expr))))
13471380

1381+
(defun inf-clojure-meta ()
1382+
"Send a form to the inferior Clojure to show its metadata"
1383+
(interactive)
1384+
(let ((proc (inf-clojure-proc))
1385+
(last-sexp (buffer-substring-no-properties (save-excursion (backward-sexp) (point)) (point))))
1386+
(inf-clojure--send-string
1387+
proc
1388+
(format (inf-clojure-meta-form proc) last-sexp))))
1389+
13481390
(defun inf-clojure-macroexpand (&optional macro-1)
13491391
"Send a form to the inferior Clojure for macro expansion.
13501392
See variable `inf-clojure-macroexpand-form'.

0 commit comments

Comments
 (0)