GithubHelp home page GithubHelp logo

vim-precious's Introduction

precious.vim

現在のカーソル位置のコンテキストによって filetype を切り換える為のプラグインです。

Set the buffer filetype based on the code block the cursor currently resides in.

The code block filetype is determined by the context_filetype.vim plugin.

Requirement

Screencapture

capture

Supported

  • c
    • masm
    • gas
  • cpp
    • masm
    • gas
  • d
    • masm
  • eruby
    • ruby
  • help
    • vim
  • html
    • javascript
    • coffee
    • css
  • int-nyaos
    • lua
  • lua
    • vim
  • nyaos
    • lua
  • perl16
    • pir
  • python
    • vim
  • vim
    • python
    • ruby
    • lua
  • vimshell
    • vim
  • xhtml
    • javascript
    • coffee
    • css
  • markdown

Example

" test.vim
" set filetype=vim --------------------------------------------------
echo "hello, world"


" set filetype=ruby -----------------------------
ruby << EOF

result = (1..10).map(&:to_s).join("-")
puts result

EOF
"---------------------------------------------------------


" set filetype=python ----------------------------
python << EOF

print map(str, range(1, 10))
print "-".join(map(str, range(1, 10)))

EOF
"---------------------------------------------------------

echo join(range(10), "-")


" autocmd
" コンテキストに入った時の処理をフック
augroup test
	autocmd!
	autocmd User PreciousFileType      :echo precious#context_filetype()
	" ruby のコンテキストに入った時に tabstop を設定する
	autocmd User PreciousFiletype_ruby :PreciousSetContextLocal tabstop=8
augroup END


" insert mode に入った時に 'filetype' を切り換える。
" カーソル移動時の自動切り替えを無効化
" let g:precious_enable_switch_CursorMoved = {
" \	"*" : 0
" \}
" let g:precious_enable_switch_CursorMoved_i = {
" \	"*" : 0
" \}
" 
" " insert に入った時にスイッチし、抜けた時に元に戻す
" augroup test
" 	autocmd!
" 	autocmd InsertEnter * :PreciousSwitch
" 	autocmd InsertLeave * :PreciousReset
" augroup END


" quickrun.vim との連携
" <Space>qic で quickrun.vim する
" filetype が切り替わってない状態でも
" コンテキストから quickrun.vim で使用する type を決定
" nmap <Space>q <Plug>(precious-quickrun-op)
" omap ic <Plug>(textobj-precious-i)
" vmap ic <Plug>(textobj-precious-i)
"------------------------------------------------------------------------------

Implementations

  • コンテキストに入った時に自動的に filetype を切り換える
  • コンテキストが切り替わった時に autocmd User で処理がフック出来る
  • コンテキストの範囲の textobj に対応
  • quickrun.vim との連携
    • コンテキストの範囲を quickrun する
    • filetype が切り替わってない状態でも type を設定

TODO

  • matcher、switcher を使用した機能の拡張
  • matcher、switcher の優先順位付け
  • コンテキストの範囲を取得

vim-precious's People

Contributors

dear avatar kawaz avatar milly avatar nilsboy avatar osyo-manga avatar siaa4fu avatar syngan avatar tiryoh avatar uga-rosa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

vim-precious's Issues

quickrun連携時にカーソル位置が移動する

タイトルの通りですが、readme に記述されているように設定して、<Space>qic を実行すると、カーソルがコンテキストの先頭に移動してします。
固定するようにできないでしょうか。

Undefined variable: k

はじめまして。vim-precious愛用しています。

きちんと中身を読めてないのですが、以下のエラーが出ます。
先月は問題なかったので、おそらくautoload/precious.vimに何かしらの不具合がある気がします。

Error detected while processing function <SNR>72_is_enable_switch_CursorMoved[1]..precious#switch_def:
line    7:
E121: Undefined variable: k
Press ENTER or type command to continue
Error detected while processing function <SNR>72_is_enable_switch_CursorMoved[1]..precious#switch_def:
line    7:
E116: Invalid arguments for function filter(copy(a:defs), {k, v -> k != '*' && k =~ '[*?\[]'       && match(a:name, glob2regpat(k)) != -1})
Press ENTER or type command to continue
Error detected while processing function <SNR>72_is_enable_switch_CursorMoved[1]..precious#switch_def:
line    7:
E15: Invalid expression: filter(copy(a:defs), {k, v -> k != '*' && k =~ '[*?\[]'       && match(a:name, glob2regpat(k)) != -1})
Press ENTER or type command to continue

使用環境

バッファが取り除かれる際の filetype のリセットが狙いとするバッファではないところで行われる

こんにちは、便利に使わせてもらっています!

filetype が base_filetype から切り替わっているときにカレントバッファ以外を取り除くと、カレントバッファで filetype のリセットが起こってしまうことがあるので報告です。

具体的には、以下の様な toml ファイルを開いたとします。

[[plugins]]
repo = 'test'
hook_add = '''
  let s:foo = 'bar'
'''

カーソルが hook_add 内にあるとき、 base_filetype である toml から context_filetype である vim に切り替わっています。このとき、例えば以下の操作のいずれかを行うと base_filetype へのリセットが起こります。

  • CTRL-W o によって他のバッファを閉じる
  • :call popup_notification('test', {}) でポップアップを開いてから閉じられるまで待つ
  • ...などなど

修整

問題は BufWinLeave 時の自動コマンドが、取り除かれつつあるバッファではなくカレントバッファで実行されることが原因です。実行すべきバッファを指定することで解決できました。

その他

また、以下の修整を加えています。

  • filetype のリセットは precious#autocmd_switch() を使う
    • 切り替えに伴い、きちんと b:precious_prev_context_filetype が上書きされるように
  • 重複する BufWinLeave 自動コマンドを削除
    • 内容的に全く同じ処理を行っていたので取り除いた

以上です

its not work

i use vim-plug:
Plug 'kana/vim-textobj-user'
Plug 'thinca/vim-quickrun'
Plug 'osyo-manga/vim-precious'
and use this:
augroup test2
autocmd!
autocmd User PreciousFileType :echo precious#context_filetype()
autocmd User PreciousFiletype_ruby :PreciousSetContextLocal tabstop=8
augroup END
after :PlugInstall, but it does't work when i move cursor.
any other required steps?

バッファ切り替えから戻った際にftがリセットされたままになる

filetype が base_filetype から切り替わっている状態で、バッファ切り替えを行うと再表示された時に base_filetype にリセットされたままになってしまう。

既存の動作

ng

  • base_filetype が toml で、hook_add 内は vim です。
  • hook_add の中に移動した後バッファを切り替えて戻ってくると vim になっていて欲しいのにtomlに戻ってしまっています。
  • 改めて一旦tomlエリアまでカーソル移動してから入り直すとvimになります(これは当然ですが)。

期待する動作

ok

  • とりあえずで BufWinEnter 時にカーソル位置の filetype を再チェックして設定してみたら期待通りになってくれました。

Unknown filetype vue-something in .vue

.vue中のscript lang="ts"のTypeScriptで行数を多くし、かつ戻り値にPromise<something>を指定すると、その行より下に行った際にvue-somethingというファイルタイプが設定されます :(

謎のファイルタイプなので、シンタックスハイライトが消失し…… x)

再現

    1. 下記ファイルの「行X」へカーソルを移動する
<template>
    <Label text="hi" />
</template>

<script lang="ts">
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a
// a

class Foo {
  public async f(): Promise<void> {}
}

function bar(): void {}
</script>

[Feature Request] Add more autocmds

How about add PreciousFileTypeLeave / PreciousFileTypeLeavePre / PreciousFileTypeLeavePre_{filetype}? They can complete missing hooks.

Useful Example (with vim-lsp):

augroup auto-lsp-diagnostics
  autocmd!
  " to avoid running wrong server on buffer
  autocmd User PreciousFileTypeLeavePre silent! LspStopServer
augroup END

filetype が元に戻らない

たとえば, /tmp/a.html に http://d.hatena.ne.jp/osyo-manga/20130612/1371046408 を貼り付けてカーソルを移動すると, filetype=javascript にはなるのですが元に戻りません。

勘違いしている/vimが古い影響かもしれませんが、PreciousFileTypeLeave_{filetype} は必須ではないような記述にみえますが、未定義の場合に発生するようです。
(autocmd の設定方法がよくわからないので、それをやれば解決できるかどうかが確認できていません。)

状況としては precious#switch() がよばれたときに最後の for 文でエラーが発生すると、b:precious_prev_context_filetype が設定されないために switch() 後も前と同じ filetype と認識してしまっているようです。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.