From aa183fa52d7bcbdef7b7244175983b6898eccd78 Mon Sep 17 00:00:00 2001 From: Buddy Sandidge Date: Wed, 19 Feb 2014 22:11:45 -0800 Subject: [PATCH] Squashed 'vim/bundle/cute-python/' content from commit 313a810d8 git-subtree-dir: vim/bundle/cute-python git-subtree-split: 313a810d858b0e1b8e20e7435bb5f728fb042dd8 --- README.markdown | 46 +++++++++++++++++++++++++++++++ after/syntax/python.vim | 35 +++++++++++++++++++++++ conceal-test.py | 61 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 142 insertions(+) create mode 100644 README.markdown create mode 100644 after/syntax/python.vim create mode 100644 conceal-test.py diff --git a/README.markdown b/README.markdown new file mode 100644 index 0000000..9940c8f --- /dev/null +++ b/README.markdown @@ -0,0 +1,46 @@ +This syntax file displays unicode characters for some Python operators and +built-in functions, turning the following: + +```python + map (lambda x: x, [1,2,3]) + + def foo(e, a): + if e in [1,2,3] and not a: + return math.sqrt(math.pi) + else: + return sum([1,2,3]) +``` + +into + +```python + map (λ x: x, [1,2,3]) + + def foo(e, a): + if e ∈ [1,2,3] ∧ ¬a: + return √(π) + else: + return ∑([1,2,3]) +``` + +Screenshot: + + + +*This does not – at any point – alter your source code*. It simply uses Vim's +"conceal" feature to “hide” `in` behind `∈`, etc. Whenever the cursor is at +a line with concealed text, the text will be expanded. + +To install, simply put `python.vim` in `~/.vim/after/syntax` or use something +like [Pathogen](https://github.com/tpope/vim-pathogen) (recommended). + +Vim ≥ 7.3 is required. + +The branch `moresymbols` includes commits from various people that add even more +conceal replacements. I try to maintain a healthy balance in the `master` +branch, but if you like to conceal even more operators or don't mind slight +inaccuracies in what mathematical symbols are used to represent, you should have +a look at the extra symbols in the `moresymbols` branch. + +This plug-in is very much inspired by + diff --git a/after/syntax/python.vim b/after/syntax/python.vim new file mode 100644 index 0000000..7f5c6a1 --- /dev/null +++ b/after/syntax/python.vim @@ -0,0 +1,35 @@ +" we need the conceal feature (vim ≥ 7.3) +if !has('conceal') + finish +endif + +" remove the keywords. we'll re-add them below +syntax clear pythonOperator + +syntax match pythonOperator "\" + +syntax match pyNiceOperator "\" conceal cchar=∈ +syntax match pyNiceOperator "\" conceal cchar=∨ +syntax match pyNiceOperator "\" conceal cchar=∧ +" include the space after “not” – if present – so that “not a” becomes “¬a”. +" also, don't hide “not” behind ‘¬’ if it is after “is ”. +syntax match pyNiceOperator "\%(is \)\@\)" conceal cchar=¬ +syntax match pyNiceOperator "\" conceal cchar=∉ +syntax match pyNiceOperator "<=" conceal cchar=≤ +syntax match pyNiceOperator ">=" conceal cchar=≥ +" only conceal “==” if alone, to avoid concealing SCM conflict markers +syntax match pyNiceOperator "=\@" conceal cchar=√ +syntax match pyNiceKeyword "\<\%(math\.\)\?pi\>" conceal cchar=π + +syntax keyword pyNiceStatement lambda conceal cchar=λ + +hi link pyNiceOperator Operator +hi link pyNiceStatement Statement +hi link pyNiceKeyword Keyword +hi! link Conceal Operator + +setlocal conceallevel=1 diff --git a/conceal-test.py b/conceal-test.py new file mode 100644 index 0000000..1d9c744 --- /dev/null +++ b/conceal-test.py @@ -0,0 +1,61 @@ +# conceal test -- lines should match + +""" +if a is not None: pass """ +if a is not None: pass + +""" +if b is None: pass """ +if b is None: pass + +""" +if 3 ∈ [1,2,3]: pass """ +if 3 in [1,2,3]: pass + +""" +if 4 ∉ [1,2,3]: pass """ +if 4 not in [1,2,3]: pass + +""" +if a ≡ b: pass """ +if a == b: pass + +""" +√(7) """ +sqrt(7) + +""" +π """ +pi + +""" +map (λ x: x, [1,2,3]) """ +map (lambda x: x, [1,2,3]) + +""" +a ∧ b """ +a and b + +""" +a ∨ b """ +a or b + +""" +∑([1,2,3]) """ +sum([1,2,3]) + +""" +if a ≢ b: pass """ +if a != b: pass + +""" +if a ≥ b: pass """ +if a >= b: pass + +""" +if a ≤ b: pass """ +if a <= b: pass + +""" +if e ∈ [1,2,3] ∧ ¬a: """ +if e in [1,2,3] and not a: