*metarw.txt* a framework to read/write a fake:path Version 0.0.4 Script ID: 2335 Copyright (C) 2008-2009 kana <http://whileimautomaton.net/> License: MIT license {{{ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. }}} CONTENTS *metarw-contents* Introduction |metarw-introduction| Interface |metarw-interface| Commands |metarw-commands| Functions |metarw-functions| Key Mappings |metarw-key-mappings| Content Browswer |metarw-content-browser| Schemes |metarw-schemes| Terms |metarw-terms| Bugs |metarw-bugs| Changelog |metarw-changelog| ============================================================================== INTRODUCTION *metarw-introduction* *metarw* is a Vim plugin to provide a framework to read/write a file-like argument of which name is written in URI-like notation such as "git:master:src/ui.c". metarw also provides content browser like |netrw|'s one for some sorts of argumetns if they are given to :edit or other command. Requirements: - Vim 7.1.299 or later Optionals: - |metarw-scheme-script| such as |metarw-git| (vimscript#2336) - |ku| (vimscript#2337) and |ku-metarw| (vimscript#2344) Demo: - http://www.screencast.com/t/fCc8cFaiQj Latest version: http://github.com/kana/config/commits/vim-metarw Document in HTML format: http://kana.github.com/config/vim/metarw.html ============================================================================== INTERFACE *metarw-interface* ------------------------------------------------------------------------------ COMMANDS *metarw-commands* :Edit[!] [++opt] [+cmd] [{file}] *:Edit* :Read [++opt] [{file}] *:Read* :Source [{file}] *:Source* :[range]Write[!] [{file}] *:Write* Same as |:edit| and other commands, but the completion of their arguments is extended to also complete fakepathes. These wrapper commands are not defined automatically. If you want them, you have to call |metarw#define_wrapper_commands()|. ------------------------------------------------------------------------------ FUNCTIONS *metarw-functions* *metarw#complete()* metarw#complete({arglead}, {cmdline}, {cursorpos}) Function for |:command-complete| to complete also fakepathes. Use as follows: "-complete=customlist,metarw#complete". *metarw#define_wrapper_commands()* metarw#define_wrapper_commands({override-p}) Define wrapper commands (see |metarw-commands|.) Override existent commands if {override-p} is true. ------------------------------------------------------------------------------ KEY MAPPINGS *metarw-key-mappings* The following key mappings are available for |metarw-content-browser|. All of them are buffer-local and defined in Normal mode: <Plug>(metarw-open-here) *<Plug>(metarw-open-here)* <Plug>(metarw-open-split) *<Plug>(metarw-open-split)* <Plug>(metarw-open-vsplit) *<Plug>(metarw-open-vsplit)* Open the item under the cursor in the current window or newly created window. If there is no item under the cursor, nothing will be happened. <Plug>(metarw-go-to-parent) *<Plug>(metarw-go-to-parent)* Open the "parent" item in the current window. The "parent" item is always the first item listed in a content browser. *g:metarw_no_default_key_mappings* The following key mappings will be also available unless g:metarw_no_default_key_mappings is defined: {lhs} {rhs} -------- ----------------------------- <Return> <Plug>(metarw-open-here) <C-m> <Plug>(metarw-open-here) o <Plug>(metarw-open-split) v <Plug>(metarw-open-vsplit) - <Plug>(metarw-go-to-parent) ------------------------------------------------------------------------------ CONTENT BROWSER *metarw-content-browser* If some sorts of fakepaths (which depend on their schemes) are given to |:edit|, |:new| or other commands, metarw will set up the newly created buffer as a content browser like |newrw|'s one for the given fakepath. In this content browser, |metarw-key-mappings| are available, and 'filetype' of a content browser is set to "metarw". Use this information for your own customization. ============================================================================== SCHEMES *metarw-schemes* To add your own scheme, write a Vim script and put it under a directory named "autoload/metarw/" in 'runtimepath'. Such script is called as a scheme script. The name of a scheme script must be "{scheme}.vim", where {scheme} is the name of the scheme. Scheme scripts must implements the following functions. Most of works such as hooking read/write events are automatically treated by metarw, so you don't have to think about troublesome stuffs. *metarw#{scheme}#complete()* metarw#{scheme}#complete({arglead}, {cmdline}, {cursorpos}) Complete the names of fakepaths. This function is like the one which is described at |:command-completion-customlist|, but there are the following differences: - {arglead} is split into "head" part and "tail" part. They must fulfill the following equation: {arglead} ==# head_part . tail_part - This function must complete candidates which are conteind in a stuff represented by the "head" part. - Return value is a list with 3 items. The first item is a list of candidates. The second item is the "head" part. The third item is the "tail" part. - Returned candidates will be filtered by callers. So don't filter in this function. For example, when completing file names and {arglead} is "foo/b": - The "head" part is "foo/". - The "tail" part is "b". - This function must complete files in the directory "foo/". metarw#{scheme}#read({fakepath}) *metarw#{scheme}#read()* Read the content of {fakepath}. This function must return a list with two items. The first item indicates the type of a return value, and the second item is an additional information for the return value. The meanings of return values are as follows: First item Second item ~ ---------- ---------------------------------- ~ *metarw#{scheme}#read()-error* "error" A string which represents an error message. *metarw#{scheme}#read()-read* "read" A string which will be given to |:read| to read the content of {fakepath}. *metarw#{scheme}#read()-browse* "browse" A list to set up |metarw-content-browser|. If the second item of return value is a list, each item in the list is a dictionary which represents an item in {fakepath}. The meaning of key-value pairs are: "label" (string) /required/ Displayed as the label of the item. "fakepath" (string) /required/ Used to open an item by |<Plug>(metarw-open-here)| or other ways. And, the first item should be the "parent" of {fakepath}. This item is used for |<Plug>(metarw-go-to-parent)|. See also |metarw-content-browser|. *metarw#{scheme}#write()* metarw#{scheme}#write({fakepath}, {line1}, {line2}, {append-p}) Write or append the content of the current buffer from {line1} to {line2} into {fakepath}. If {append-p} is true, does appending instead of writing. This function must return a list with one or more items like |metarw#{scheme}#read()|, but the meanings of return values are as follows: First item Rest items ~ ---------- ----------------------------------- ~ *metarw#{scheme}#write()-error* "error" The second item must be a string which represents an error message. *metarw#{scheme}#write()-write* "write" The second item must be a string which will be given to |:write| to write the content of {fakepath}. The third item is optional; if it is given, it must be a string which is a Vim script and it will be |:execute|d after writing. *metarw#{scheme}#write()-done* "done" The rest items are just ignored. This type means that writing is already done by |metarw#{scheme}#write()|. Don't reset 'modified' in this function. It will be automatically treated by metarw. ============================================================================== TERMS *metarw-terms* Fakepath *metarw-fakepath* Fakepathes are file-like arguments written in URI-like notation. For example, "git:master:src/ui.c" is a fakepath. Scheme *metarw-scheme* Scheme is the substring before the first ":" in the name of a fakepath. For example, the scheme of "git:master:src/ui.c" is "git". The name of a scheme must consist of 2 or more characters, and it should consist of only lowercase, English alphabets. Scheme script *metarw-scheme-script* Support script to enable to read/write fakepathes. One scheme script supports just one scheme. ============================================================================== BUGS *metarw-bugs* - {range} for ":read {fakepath}" is ignored and it will always be treated as the current line. Because there is no way to get {range} in |FileReadCmd|. - There are many bugs around the world. ============================================================================== CHANGELOG *metarw-changelog* 0.0.4 2009-05-23T14:51:43+09:00 *metarw-changelog-0.0.4* - Refine the document. - |metarw#{scheme}#write()|: - Fix a bug that some kind of errors are not handled properly. - Add a way to execute a script after writing. See |metarw#{scheme}#write()-write| for the details. 0.0.3 2008-08-30T03:11:55+09:00 *metarw-changelog-0.0.3* - |metarw#{scheme}#write()|: - Fix wrong implementation. - Add new type of return value "done". 0.0.2 2008-08-10T23:43:48+09:00 *metarw-changelog-0.0.2* - Separate |ku-metarw| as a independent package. 0.0.1 2008-08-10T12:19:52+09:00 *metarw-changelog-0.0.1* - Add a special source of ku (see |metarw-schemes-as-ku-sources|). - Fix autocommands not to hook fakepaths with any schene name which consists of less than 2 characters. Old definitions incorrectly recognized paths with a drive letter in Microsoft Windows environment as a fakepath. (thanks to id:thinca) - Add 2 rules on the name of a scheme (see |metarw-scheme|). - Fix plugin/metarw.vim to be properly reloadable. - Fix requirements - metarw uses |fnameescape()| which is added since Vim 7.1.299. (thanks to id:thinca) 0.0.0 2008-07-11T16:51:59+09:00 *metarw-changelog-0.0.0* - Initial version. ============================================================================== vim:tw=78:ts=8:ft=help:norl:fen:fdl=0:fdm=marker: