Back
ns-resolve (clj)
(source)function
(ns-resolve ns sym)
(ns-resolve ns env sym)
Returns the var or Class to which a symbol will be resolved in the
namespace (unless found in the environment), else nil. Note that
if the symbol is fully qualified, the var/Class to which it resolves
need not be present in the namespace.
Examples
clojure/core.typed
(ns ^:no-doc clojure.core.typed.import-macros
(:require [clojure.core :as core]))
;copied from ClojureScript
(defmacro import-macros [ns [& vars]]
(core/let [ns (find-ns ns)
vars (map (core/fn [vsym]
{:pre [(symbol? vsym)]
:post [(instance? clojure.lang.Var %)]}
(let [v (ns-resolve ns vsym)]
(assert v (str "Internal error: " vsym " does not exist"))
v))
vars)
syms (map (core/fn [^clojure.lang.Var v]
{:pre [(instance? clojure.lang.Var v)]
:post [(symbol? %)]}
(core/-> v .sym (with-meta {:macro true})))
vars)
defs (map (core/fn [sym var]
{:pre [(symbol? sym)
(instance? clojure.lang.Var var)]}
`(do (def ~sym (deref ~var))
;for AOT compilation
(alter-meta! (var ~sym)
merge
(dissoc (meta ~var) :ns :name)
{:macro true})))
syms vars)]
`(do ~@defs
:imported)))
hraberg/deuce
(ns deuce.emacs.term
(:use [deuce.emacs-lisp :only (defun defvar)])
(:require [clojure.core :as c]
[deuce.emacs.data :as data]
[deuce.emacs.eval :as eval]
[deuce.emacs.terminal :as terminal])
(:import [com.googlecode.lanterna.screen Screen])
(:refer-clojure :exclude []))
TTY may be a terminal object, a frame, or nil (meaning the selected
frame's terminal)."
(when-let [terminal ^Screen (terminal/frame-terminal)]
(.startScreen terminal)
((ns-resolve 'deuce.main 'start-ui))
(eval/run-hook-with-args 'resume-tty-functions terminal)))
A suspended tty may be resumed by calling `resume-tty' on it."
(when-let [terminal ^Screen (terminal/frame-terminal)]
((ns-resolve 'deuce.main 'stop-ui))
(.stopScreen terminal)
(eval/run-hook-with-args 'suspend-tty-functions terminal)))
hraberg/deuce
(ns deuce.emacs.marker
(:use [deuce.emacs-lisp :only (defun defvar) :as el])
(:require [clojure.core :as c]
[deuce.emacs.alloc :as alloc]
[deuce.emacs.buffer :as buffer]
[deuce.emacs.data :as data])
(:import [deuce.emacs.data Buffer BufferText Marker])
(:refer-clojure :exclude []))
(defun copy-marker (&optional marker type)
"Return a new marker pointing at the same place as MARKER.
If argument is a number, makes a new marker pointing
at that position in the current buffer.
If MARKER is not specified, the new marker does not point anywhere.
The optional argument TYPE specifies the insertion type of the new marker;
see `marker-insertion-type'."
((ns-resolve 'deuce.emacs.buffer 'allocate-marker) type
(buffer/current-buffer) (if (data/markerp marker)
@(.charpos ^Marker marker)
(el/check-type 'integerp marker))))
hraberg/deuce
(ns deuce.emacs
(:require [clojure.core :as c]
[deuce.emacs-lisp :as el]
[deuce.emacs-lisp.globals :as globals])
(:refer-clojure :only [])
(:use [deuce.emacs-lisp :only [and apply-partially catch cond condition-case defconst define-compiler-macro defmacro
defun defvar function if interactive lambda let let* or prog1 prog2 progn quote
save-current-buffer save-excursion save-restriction setq setq-default
unwind-protect while throw]]
[deuce.emacs.alloc]
[deuce.emacs.buffer]
[deuce.emacs.bytecode]
[deuce.emacs.callint]
[deuce.emacs.callproc]
[deuce.emacs.casefiddle]
[deuce.emacs.casetab]
[deuce.emacs.category]
[deuce.emacs.ccl]
[deuce.emacs.character]
[deuce.emacs.charset]
[deuce.emacs.chartab]
[deuce.emacs.cmds]
[deuce.emacs.coding]
[deuce.emacs.composite]
[deuce.emacs.data]
[deuce.emacs.dired]
[deuce.emacs.dispnew]
[deuce.emacs.doc]
[deuce.emacs.editfns]
[deuce.emacs.emacs]
[deuce.emacs.eval]
[deuce.emacs.fileio]
[deuce.emacs.filelock]
[deuce.emacs.floatfns]
[deuce.emacs.fns]
[deuce.emacs.font]
[deuce.emacs.frame]
[deuce.emacs.indent]
[deuce.emacs.insdel]
[deuce.emacs.keyboard]
[deuce.emacs.keymap]
[deuce.emacs.lread]
[deuce.emacs.macros]
[deuce.emacs.marker]
[deuce.emacs.menu]
[deuce.emacs.minibuf]
[deuce.emacs.print]
[deuce.emacs.process]
[deuce.emacs.search]
[deuce.emacs.syntax]
[deuce.emacs.term]
[deuce.emacs.terminal]
[deuce.emacs.textprop]
[deuce.emacs.undo]
[deuce.emacs.window]
[deuce.emacs.xdisp]
[deuce.emacs.xfaces]
[deuce.emacs.xml]))
;; I'm the one and only Frame
(setq terminal-frame ((c/ns-resolve 'deuce.emacs.frame 'make-initial-frame)))
(setq last-event-frame terminal-frame)
;; Callback run by faces/tty-run-terminal-initialization based on deuce.emacs.term/tty-type returning "lanterna"
(defun terminal-init-lanterna ()
(c/require 'deuce.main)
((c/ns-resolve 'deuce.main 'terminal-init-lanterna)))
hraberg/deuce
(ns deuce.emacs.alloc
(:use [deuce.emacs-lisp :only (defun defvar) :as el]
[taoensso.timbre :as timbre
:only (trace debug info warn error fatal spy)])
(:require [clojure.core :as c]
[clojure.walk :as w]
[deuce.emacs-lisp.cons :as cons])
(:refer-clojure :exclude [vector cons list])
(:import [java.util Arrays]
[java.lang.management ManagementFactory MemoryNotificationInfo MemoryType MemoryPoolMXBean]
[javax.management NotificationListener NotificationEmitter Notification]))
(defun make-marker ()
"Return a newly allocated marker which does not point at any place."
((ns-resolve 'deuce.emacs.buffer 'allocate-marker) nil nil nil))
(defun #el/sym "/=" (num1 num2)
"Return t if first arg is not equal to second arg. Both must be numbers or markers."
(not ((ns-resolve 'deuce.emacs.data '=) num1 num2)))