Skip to content

Athenacle/spacemacs.d

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spacemacs.d

https://cdn.rawgit.com/syl20bnr/spacemacs/442d025779da2f62fc86c2082703697714db6514/assets/spacemacs-badge.svg

Content

Spacemacs

Spacemacs is A community-driven Emacs distribution

Layers

- ebuild ebuild file mode.

Configuration

Keys

Magit Keys

Prefix: SPC gz

KeyDescriptionAvailable ModeGroup
SPC gzpMagit Pull PopupAllGit
SPC gzfMagit Fetch PopupAllGit
SPC gzPMagit Push PopupAllGit

LSP Keys

Prefix SPC mn

KeyDescriptionAvailable ModeGroup
SPC mndLSP Find DefinitionsGo/Javascript/Python/Java/C/C++/ObjCLSP
SPC mnrLSP File ReferencesGo/Javascript/Python/Java/C/C++/ObjCLSP
SPC mnsLSP Find Workspace SymbolsGo/Javascript/Python/Java/C/C++/ObjCLSP
SPC mncClear Buffer DelimitersGo/Javascript/Python/Java/C/C++/ObjCLSP

Library References

Lisp Function List

athenacle|parse-args

  • Extract keys keyword and body arguments from args, put all key arguments into hashtable, put body expressions into list. Returns (cons hashtable =body)
  • (defun athenacle|parse-args (keys args))
    • keys list
    • args list
  • 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'

athenacle|lib-build-lambda-from-sexps

  • Build anonymous lambda function which parameters are args and body are list of sexp list-of-sexp
  • (defun athenacle|lib-build-lambda-from-sexps (args list-of-sexp))
    • args list
    • list-of-sexp list
  • 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")

Lisp Macro List

athenacle||lib-call-if

  • Call func when pred is not nil, with arguments object and others
  • (defmacro athenacle||lib-call-if pred func &optional object others)
    • pred function
    • func function
    • object emacs object optional
    • others list optional
  • 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

athenacle||lib-macro

  • Build MACRO called name, it has a list of keys keyword parameters, and it has its own body.
  • (cl-defmacro athenacle||lib-macro (name keys &rest rest))
    • name symbol
    • keys list
    • rest list
  • 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

LSP

athenacle|start-lsp

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)))))

Add New LSP Backend

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)

Misc Files

Description

Calculate Layers List according to dotspacemacs-configuration-layers. It is used for sync layer directory to tmpfs.

Example Bash Code

#!/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"

License

GPLv3

Contact

zjjhwxc(at)gmail.com

About

spacemacs configurations

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published