Skip to content

Commit

Permalink
Discovered a way to put comments within dict defs in Vim script
Browse files Browse the repository at this point in the history
  • Loading branch information
axvr committed Oct 4, 2024
1 parent 01edfec commit 9b5e42c
Showing 1 changed file with 30 additions and 45 deletions.
75 changes: 30 additions & 45 deletions indent/clojure.vim
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ setlocal softtabstop=2 shiftwidth=2 expandtab
setlocal indentkeys=!,o,O

" Set a new configuration option with a default value. Assigns a script-local
" version too, which is the default fallback in case the global was "unlet".
" version too, to be used as a default fallback if the global was "unlet".
function! s:SConf(name, default) abort
let s = 's:' . a:name
let n = 'g:' . a:name
let [s, g] = ['s:' . a:name, 'g:' . a:name]
exec 'let' 's:' . a:name '=' string(a:default)
if ! exists(n) | exec 'let' n '=' s | endif
if ! exists(g) | exec 'let' g '=' s | endif
endfunction

" Get the value of a configuration option with a possible fallback.
Expand All @@ -51,47 +50,33 @@ call s:SConf('clojure_fuzzy_indent_patterns', [
\ ])

" Defaults copied from: https://github.com/clojure-emacs/clojure-mode/blob/0e62583b5198f71856e4d7b80e1099789d47f2ed/clojure-mode.el#L1800-L1875
if !exists('g:clojure_indent_rules')
let g:clojure_indent_rules = {
\ 'ns': 1,
\ 'fn': 1, 'def': 1, 'defn': 1, 'bound-fn': 1, 'fdef': 1,
\ 'let': 1, 'binding': 1, 'defmethod': 1,
\ 'if': 1, 'if-not': 1, 'if-some': 1, 'if-let': 1,
\ 'when': 1, 'when-not': 1, 'when-some': 1, 'when-let': 1, 'when-first': 1,
\ 'case': 1, 'cond': 0, 'cond->': 1, 'cond->>': 1, 'condp': 2,
\ 'while': 1, 'loop': 1, 'for': 1, 'doseq': 1, 'dotimes': 1,
\ 'do': 0, 'doto': 1, 'comment': 0, 'as->': 2,
\ 'delay': 0, 'future': 0, 'locking': 1,
\ 'try': 0, 'catch': 2, 'finally': 0,
\ 'reify': 1, 'proxy': 2, 'defrecord': 2, 'defprotocol': 1, 'definterface': 1,
\ 'extend': 1, 'extend-protocol': 1, 'extend-type': 1
\ }
" (letfn) (1 ((:defn)) nil)
" (reify) (:defn (1))
" (deftype defrecord proxy) (2 nil nil (:defn))
" (defprotocol definterface extend-protocol extend-type) (1 (:defn))

" ClojureScript
call extend(g:clojure_indent_rules, {
\ 'this-as': 1, 'specify': 1, 'specify!': 1
\ })
" (specify specify!) (1 :defn)

" clojure.test
call extend(g:clojure_indent_rules, {
\ 'deftest': 1, 'testing': 1, 'use-fixtures': 1, 'are': 2
\ })

" core.async
call extend(g:clojure_indent_rules, {
\ 'alt!': 0, 'alt!!': 0, 'go': 0, 'go-loop': 1, 'thread': 0
\ })

" core.logic
call extend(g:clojure_indent_rules, {
\ 'run': 1, 'run*': 1, 'fresh': 1
\ })
endif
call s:SConf('clojure_indent_rules', {
\ 'ns': 1,
\ 'fn': 1, 'def': 1, 'defn': 1, 'bound-fn': 1, 'fdef': 1,
\ 'let': 1, 'binding': 1, 'defmethod': 1,
\ 'if': 1, 'if-not': 1, 'if-some': 1, 'if-let': 1,
\ 'when': 1, 'when-not': 1, 'when-some': 1, 'when-let': 1, 'when-first': 1,
\ 'case': 1, 'cond': 0, 'cond->': 1, 'cond->>': 1, 'condp': 2,
\ 'while': 1, 'loop': 1, 'for': 1, 'doseq': 1, 'dotimes': 1,
\ 'do': 0, 'doto': 1, 'comment': 0, 'as->': 2,
\ 'delay': 0, 'future': 0, 'locking': 1,
\ 'try': 0, 'catch': 2, 'finally': 0,
\ 'reify': 1, 'proxy': 2, 'defrecord': 2, 'defprotocol': 1, 'definterface': 1,
\ 'extend': 1, 'extend-protocol': 1, 'extend-type': 1,
"\ (letfn) (1 ((:defn)) nil)
"\ (reify) (:defn (1))
"\ (deftype defrecord proxy) (2 nil nil (:defn))
"\ (defprotocol definterface extend-protocol extend-type) (1 (:defn))
"\ ClojureScript
\ 'this-as': 1, 'specify': 1, 'specify!': 1,
"\ (specify specify!) (1 :defn)
"\ clojure.test
\ 'deftest': 1, 'testing': 1, 'use-fixtures': 1, 'are': 2,
"\ core.async
\ 'alt!': 0, 'alt!!': 0, 'go': 0, 'go-loop': 1, 'thread': 0,
"\ core.logic
\ 'run': 1, 'run*': 1, 'fresh': 1
\ })

" Returns "1" if position "i_char" in "line_str" is preceded by an odd number
" of backslash characters (i.e. escaped).
Expand Down

0 comments on commit 9b5e42c

Please sign in to comment.