Skip to content

[Fix #57] Add inf-clojure-meta #157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## master (unreleased)

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

## 2.1.0 (2018-01-02)

Expand Down
42 changes: 42 additions & 0 deletions inf-clojure.el
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,39 @@ If you are using REPL types, it will pickup the most approapriate

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

;;; Metadata
;;; ===================
(defcustom inf-clojure-meta-format
"(clojure.core/meta %s)"
"Form to retrieve metadata of another form."
:type 'string
:safe #'stringp
:package-version '(inf-clojure . "2.2.0"))

(defcustom inf-clojure-meta-format-planck
"(meta %s)"
"Planck form to retrieve metadata of another form."
:type 'string
:safe #'stringp
:package-version '(inf-clojure . "2.2.0"))

(defcustom inf-clojure-meta-format-lumo
"(meta %s)"
"Lumo form to retrieve metadata of another form."
:type 'string
:safe #'stringp
:package-version '(inf-clojure . "2.2.0"))

(defun inf-clojure-meta-form (proc)
"Return the form for retrieving metadata in the Inf-Clojure PROC.
If you are using REPL types, it will pickup the most appropriate
`inf-clojure-meta-format` variant."
(inf-clojure--sanitize-command
(pcase (inf-clojure--set-repl-type proc)
(`lumo inf-clojure-meta-format-lumo)
(`planck inf-clojure-meta-format-planck)
(_ inf-clojure-meta-format))))

;;; Ancillary functions
;;; ===================

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

(defun inf-clojure-meta ()
"Send a form to the inferior Clojure to show its metadata."
(interactive)
(let ((proc (inf-clojure-proc))
(last-sexp (buffer-substring-no-properties (save-excursion (backward-sexp) (point)) (point))))
(inf-clojure--send-string
proc
(format (inf-clojure-meta-form proc) last-sexp))))

(defun inf-clojure-macroexpand (&optional macro-1)
"Send a form to the inferior Clojure for macro expansion.
See variable `inf-clojure-macroexpand-form'.
Expand Down