Created
March 29, 2012 15:01
-
-
Save amzyang/2238243 to your computer and use it in GitHub Desktop.
use :Dactyl command to control pentadactyl directly in vim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (!exists('g:firefox_execute') || empty(g:firefox_execute)) | |
let g:firefox_execute = 'firefox' | |
endif | |
fun! DactylComplete(A, L, P) "{{{ | |
if (!exists('g:DactylCompleteLoaded')) | |
let l:tmp = tempname() | |
let l:getListCommands = 'js let hives = modules.commands.allHives;' | |
\ .'var names = [];' | |
\ .'Array.forEach(hives, function(hive) {' | |
\ .' let lists = hive._list;' | |
\ .' Array.forEach(lists, function(list) {' | |
\ .' names = names.concat(list.names);' | |
\ .' });' | |
\ .'});' | |
\ .'names.sort();' | |
\ .'uniqueNames = names.filter(function(elem, pos) names.indexOf(elem) == pos);' | |
\ .'names = uniqueNames;' | |
\ .'var localFile = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);' | |
\ .'try {' | |
\ .printf(' localFile.initWithPath("%s");', l:tmp) | |
\ .' if (!localFile.exists() || (!localFile.isDirectory())) {' | |
\ .' Components.utils.import("resource://gre/modules/NetUtil.jsm");' | |
\ .' Components.utils.import("resource://gre/modules/FileUtils.jsm");' | |
\ .' var ostream = FileUtils.openSafeFileOutputStream(localFile);' | |
\ .' var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Components.interfaces.nsIScriptableUnicodeConverter);' | |
\ .' converter.charset = "UTF-8";' | |
\ .' var istream = converter.convertToInputStream(names.join("\n"));' | |
\ .' NetUtil.asyncCopy(istream, ostream, function(status) {' | |
\ .' if (!Components.isSuccessCode(status)) {' | |
\ .' return;' | |
\ .' }' | |
\ .' });' | |
\ .' } else {' | |
\ .' dactyl.echoerr("Unable to save file!");' | |
\ .' }' | |
\ .'} catch (e) {' | |
\ .' dactyl.echoerr("failed!");' | |
\ ."}" | |
sil call system(printf("%s -pentadactyl-remote \"%s\"", shellescape(g:firefox_execute, 1), escape(l:getListCommands, "\""))) | |
try | |
let g:DactylCommands = readfile(l:tmp) | |
let g:DactylCompleteLoaded = 1 | |
catch | |
echoerr "Completion failed, maybe firefox isn't running." | |
return [] | |
endtry | |
endif | |
let l:args = g:DactylCommands | |
let l:valid_completes = [] | |
for l:arg in l:args | |
if stridx(l:arg, a:A) == 0 | |
let l:valid_completes += [l:arg] | |
endif | |
endfor | |
return l:valid_completes | |
endfunction "}}} | |
" FIXME: :Dactyl echo <></> | |
" FIXME: let it work on Windows | |
command! -complete=customlist,DactylComplete -nargs=* Dactyl sil call system(printf("%s -pentadactyl-remote \"%s\"", shellescape(g:firefox_execute, 1), escape(<q-args>, "\""))) |
Unfortunately, it doesn't work on Windows.
It doesn't work on Mac OS X too.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
use :Dactyl to run pentadactyl ex commands.
for example:
:Dactyl pwd
You can use 'g:firefox_execute' variable to specify the location of your firefox execute.