guns / vim-clojure-static

Meikel Brandmeyer's excellent Clojure runtime files
Other
420 stars 50 forks source link

Switching between Clojure and Scheme buffers breaks indentation settings #43

Closed d11wtq closed 10 years ago

d11wtq commented 10 years ago

I'm not sure if this is a bug in vim-clojure-static, Vim itself, or something else. In a freshly opened Vim (7.3), if I open a Scheme file before anything else, I get the correct indentation for Scheme code. If I then switch to a Clojure buffer, nothing is indented correctly; as if it still thinks I'm editing Scheme (e.g. the (:require ... ) forms in a (ns ... ) are indented aligned with the namespace name, instead of under the 's'.

Likewise, if the first buffer I open is a Clojure buffer, my Clojure code is indented correctly, but when I switch to a Scheme buffer, it refuses to indent correctly (e.g. the body of a (define (x y z) ... ) form indents in line with the parameter list.

d11wtq commented 10 years ago

EDIT | Apologies, I can't get GitHub's Markdown parser to render the code blocks in the list.

On closer inspection, it looks like lispwords is being clobbered. Vim recognizes syntax as 'scheme' or 'clojure', but set lispwords? shows me only the Clojure special forms even in a Scheme buffer.

Interestingly, the opposite doesn't seem to be true when I open the Scheme buffer first.

  1. Open Scheme buffer
:set lispwords?
      lispwords=defun,define,defmacro,set!,lambda,if,case,let,flet,let*,letrec,do,do*,define-syntax,let-syntax,letrec-s
yntax,destructuring-bind,defpackage,defparameter,defstruct,deftype,defvar,do-all-symbols,do-external-symbols,do-sym
bols,dolist,dotimes,ecase,etypecase,eval-when,labels,macrolet,multiple-value-bind,multiple-value-call,multiple-valu
e-prog1,multiple-value-setq,prog1,progv,typecase,unless,unwind-protect,when,with-input-from-string,with-open-file,w
ith-open-stream,with-output-to-string,with-package-iterator,define-condition,handler-bind,handler-case,restart-bind
,restart-case,with-simple-restart,store-value,use-value,muffle-warning,abort,continue,with-slots,with-slots*,with-a
ccessors,with-accessors*,defclass,defmethod,print-unreadable-object
  1. Switch to a Clojure buffer
:set lispwords?
      lispwords=bound-fn,def,definline,definterface,defmacro,defmethod,defmulti,defn,defn-,defonce,defprotocol,defrecor
d,defstruct,deftest,deftest-,deftype,extend,extend-protocol,extend-type,fn,ns,proxy,reify,set-test,as->,binding,doa
ll,dorun,doseq,dotimes,doto,for,if-let,let,letfn,locking,loop,testing,when-first,when-let,with-bindings,with-in-str
,with-local-vars,with-open,with-precision,with-redefs,with-redefs-fn,with-test,case,cond->,cond->>,condp,if,if-not,
when,when-not,while,catch
  1. Switch back to the Scheme buffer
:set lispwords?`
      lispwords=bound-fn,def,definline,definterface,defmacro,defmethod,defmulti,defn,defn-,defonce,defprotocol,defrecor
d,defstruct,deftest,deftest-,deftype,extend,extend-protocol,extend-type,fn,ns,proxy,reify,set-test,as->,binding,doa
ll,dorun,doseq,dotimes,doto,for,if-let,let,letfn,locking,loop,testing,when-first,when-let,with-bindings,with-in-str
,with-local-vars,with-open,with-precision,with-redefs,with-redefs-fn,with-test,case,cond->,cond->>,condp,if,if-not,
when,when-not,while,catch

It looks like vim-clojure-static clobbered the lispwords setting. Missing a setlocal, perhaps?

guns commented 10 years ago

Hello, thanks for reporting!

It looks like vim-clojure-static clobbered the lispwords setting. Missing a setlocal, perhaps?

It seems the problem is actually that lispwords is a global setting when it should really be a global-local setting.

Only three filetypes ever touch lispwords: clojure, art, and scheme. The scheme ftplugin, unlike the other two, only appends extra words onto lispwords if g:is_mzscheme or g:is_chicken is true. (Try repeating your experiment after setting one of these options; ugh)

All three scripts also register a reset-to-default setlocal lispwords< in the ftplugin/indent undo hooks, but this does not actually work because lispwords is global, not global-local.

I'd like to send a patch upstream for this rather than attempt to hack around it here. I will post a link to the mailing list thread here when it happens.

d11wtq commented 10 years ago

Thank you! I was not aware of the existence of global vs global-local variables. I'll be able to hack around it for now anyway :)

guns commented 10 years ago

Okay, I've sent patches upstream:

https://groups.google.com/forum/#!topic/vim_dev/6Abi8nsY2Dc

Let's hope they approve.

d11wtq commented 10 years ago

Awesome, kudos! :)

guns commented 10 years ago

Bram merged the 'lispwords' patch as 7.4.201:

https://groups.google.com/forum/#!topic/vim_dev/AXWalJt-RNQ

Could you please confirm that this patch/version addresses this issue?

d11wtq commented 10 years ago

Oh, excellent. I'll fire up a docker container and install Vim from mercurial later to try it out :)

d11wtq commented 10 years ago

Just tested it now. Works a treat, thanks heaps for sorting it out!

guns commented 10 years ago

Great, thanks for reporting/