Spacemacs
is A community-driven Emacs distribution
- athenacle-markdown A fork of official markdown layer. Added some other configurations.
Prefix: SPC gz
Key | Description | Available Mode | Group |
---|---|---|---|
SPC gzp | Magit Pull Popup | All | Git |
SPC gzf | Magit Fetch Popup | All | Git |
SPC gzP | Magit Push Popup | All | Git |
Prefix SPC mn
Key | Description | Available Mode | Group |
---|---|---|---|
SPC mnd | LSP Find Definitions | Go/Javascript/Python/Java/C/C++/ObjC | LSP |
SPC mnr | LSP File References | Go/Javascript/Python/Java/C/C++/ObjC | LSP |
SPC mns | LSP Find Workspace Symbols | Go/Javascript/Python/Java/C/C++/ObjC | LSP |
SPC mnc | Clear Buffer Delimiters | Go/Javascript/Python/Java/C/C++/ObjC | LSP |
- Extract
keys
keyword andbody
arguments fromargs
, put all key arguments into hashtable, putbody
expressions into list. Returns (conshashtable
=body) (defun athenacle|parse-args (keys args))
- keys
list
- args
list
- keys
- Sample
(athenacle|parse-args (a b c d) (:a "a" :b "b" :c "c" (sexp-1) (sexp-2) (sexp-3)))
;; ==>>
;; (#<hash-table equal 3/5 0x2d275e1>
;; (sexp-1)
;; (sexp-2)
;; (sexp-3))
;; in hashtable, a -> "a" b -> "b" c -> "c". d doesnot exist in hashtable, so, when we try to (get-hash "d" hashtable) -> nil
;; => (car (athenacle|parse-args ...) will get `hashtable', aka keyword argument,
;; => (cdr (athenacle|parse-args ...) will get `list', which can be processed by `eval'
- Build anonymous lambda function which parameters are
args
and body are list of sexplist-of-sexp
(defun athenacle|lib-build-lambda-from-sexps (args list-of-sexp))
- args
list
- list-of-sexp
list
- args
- Sample
(setq msg
(athenacle|lib-build-lambda-from-sexps '(a b c) '((message "%s" a) (message "%s" b) (message "%s" c))))
;; msg ==>>
;; (lambda
;; (a b c)
;; nil
;; (message "%s" a)
;; (message "%s" b)
;; (message "%s" c))
(funcall msg "a" "b" "c")
- Call
func
whenpred
is not nil, with argumentsobject
andothers
(defmacro athenacle||lib-call-if pred func &optional object others)
- pred
function
- func
function
- object
emacs object
optional - others
list
optional
- pred
- Sample
;; definition (defmacro athenacle||lib-call-if (pred func &optional object others) "Test function PRED, if it eval as not nil, apply OBJECT to FUNC. When FUNC is nil, set it to `message'." `(when (funcall ,pred) (apply (quote ,func) (cons ,object ,others)))) (athenacle|start-lsp go-mode :start go-go-go-go-enable) ;; sample (athenacle||lib-call-if (lambda () t) message "sample %s message" '("usage")) ;; expand (macro-expand '(athenacle||lib-call-if (lambda () t) message "sample %s message" '("usage"))) ;; ==> ;; (if ;; (funcall ;; (lambda nil t)) ;; (progn ;; (apply 'message ;; (cons "sample %s message" ;; '("usage")))))
- Related Macros
athenacle||lib-call-if-debug-on-error
athenacle||lib-message-if-debug-on-error
- Build MACRO called
name
, it has a list ofkeys
keyword parameters, and it has its own body. (cl-defmacro athenacle||lib-macro (name keys &rest rest))
- name
symbol
- keys
list
- rest
list
- name
body
parameters: the body part of name object- Sample
(athenacle||lib-macro test-macro (a b c) (message "in test-macro" ) (funcall body)) ;; note this `body' object ;; ==>> test-macro ;; this expression will define a macro `test-macro' which just like (lambda (body a b c) (message "in-test-macro") (funcall body)) (test-macro :a "I am a" :b 10 (message "a: %s" a) (message "b: %d" b) (message "c: %s" c)) ;; ==>> ;; in test-macro ;; a: I am a ;; b: 10 ;; c: nil ;; this expression will call the lambda above with argument: a -> "I am a" b -> 10 c -> nil ;; body -> ;; (lambda() ;; (message "a: %s" a) ;; (message "b: %d" b) ;; (message "c: %s" c))
- Related Macros
athenacle||add-package
- Related Macros
athenacle|start-lsp
is a macro defined in init-lsp.el
(cl-defmacro athenacle|start-lsp(mode &key (start nil) (before nil) (after nil))
"Main start-lsp macro
MODE: enable LSP for major mode
START: LSP starting function. If it is `nil', a default function such as `lsp-go-enable' is called.
BEFORE: function that should be called before `START'
AFTER: function called after `START'
."
(message "enable start-lsp: mode: %s, start: %s, before: %s, after: %s" mode start before after)
(setq before (if before before #'(lambda())))
(setq after (if after after #'(lambda())))
(setq mode-hook-name (intern (format "%s-hook" mode)))
(setq start-func-name (if start start (intern (format "lsp-%s-enable" (car (split-string (symbol-name mode) "-"))))))
`(add-hook (quote ,mode-hook-name)
(lambda() (progn
(,before)
(with-eval-after-load 'lsp-mode
(require 'lsp-flycheck))
(flycheck-mode t)
(when (athenacle|spacemacs-enabled)
(spacemacs|add-company-backends :modes ,mode :backends company-lsp)
(spacemacs|diminish lsp-mode " Ⓛ " " L ")
(spacemacs/declare-prefix-for-mode (quote ,mode) "mn" "lsp tools")
(spacemacs/set-leader-keys-for-major-mode (quote ,mode)
"nd" 'lsp-ui-peek-find-definitions
"nr" 'lsp-ui-peek-find-references
"ns" 'lsp-ui-peek-find-workspace-symbol
"nc" 'athenacle-lsp/clear-buffer-delimiters))
(,start-func-name)
(,after)))))
All have to do is require
lsp-package and then call athenacle|start-lsp
. The defualt start funtion is generated by the macro
;; method 1
(require 'go-lsp)
(athenacle|start-lsp go-mode) ;; this will call `lsp-go-enable'
;; method 2
(require 'lsp-mode)
(lsp-define-stdio-client
go-go-go-go ;; funciont name will be `go-go-go-go-enable'
"go"
(lsp-make-traverser #'(lambda (dir)
(directory-files dir nil "main.go")))
`(,athenacle|go-server, "-mode=stdio")
:initialize
(lambda (client)
(lsp-provide-marked-string-renderer client "go" (athenacle|make-renderer "go")))
:ignore-regexps
'("^langserver-go: reading on stdin, writing on stdout$"))
(athenacle|start-lsp go-mode :start go-go-go-go-enable)
Calculate Layers List according to dotspacemacs-configuration-layers
. It is used for sync layer directory to tmpfs.
#!/bin/bash
emacs_path="$HOME"/.config/.emacs.d
emacs_generate_rsync_list_path="$HOME"/.spacemacs.d/generate-rsync-list.el
cd "$emacs_path" || exit
include_path="$(mktemp)"
echo "$emacs_path"
emacs -Q --script "$emacs_generate_rsync_list_path" "$emacs_path" "$include_path"
cat >> "$include_path" << EOF
init.el
elpa/
core/
.cache/
private/
.lock
EOF
rsync -ar "$emacs_path" /tmp/emacs --files-from="$include_path" --exclude "*.org"
rm "$include_path"