From 8542a995879e1f05b9921f88563bdf4cc52a741d Mon Sep 17 00:00:00 2001
From: anekos
Date: Sat, 13 Dec 2008 09:19:19 +0000
Subject: カレントディレクトリを考慮するようにした。 (expandPath
にパッチするべき?)
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@26629 d0d07461-0603-4401-acd4-de1884942a52
---
auto_source.js | 28 +++++++++++++++++++++-------
1 file changed, 21 insertions(+), 7 deletions(-)
(limited to 'auto_source.js')
diff --git a/auto_source.js b/auto_source.js
index 2357cb9..1b7284d 100644
--- a/auto_source.js
+++ b/auto_source.js
@@ -3,7 +3,7 @@ var PLUGIN_INFO =
Auto Source
Sourcing automatically when the specified file is modified.
指定のファイルが変更されたら自動で :so する。
- 1.2
+ 1.3
anekos
2.0pre
2.0pre
@@ -52,16 +52,30 @@ var PLUGIN_INFO =
function remove (filepath, func)
(files = files.filter(function (it) (it.path.indexOf(filepath) !== 0 && (func(it)+'-'))));
+ function expandPath (filepath) {
+ filepath = io.expandPath(filepath);
+ if (filepath.match(/\/|\w:[\\\/]/))
+ return filepath;
+ let cur = io.getCurrentDirectory();
+ cur.appendRelativePath(filepath);
+ return cur.path;
+ }
+
function startWatching (filepath) {
if (exists(filepath))
throw 'The file has already been watched: ' + filepath;
let last = firstTime ? null : getFileModifiedTime(filepath);
let handle = setInterval(function () {
- let current = getFileModifiedTime(filepath);
- if (last != current) {
- liberator.log('sourcing: ' + filepath);
- last = current;
- io.source(filepath);
+ try {
+ let current = getFileModifiedTime(filepath);
+ if (last != current) {
+ liberator.log('sourcing: ' + filepath);
+ last = current;
+ io.source(filepath);
+ }
+ } catch (e) {
+ killWatcher(filepath);
+ liberator.echoerr('Error! ' + filepath);
}
}, interval);
files.push({handle: handle, path: filepath});
@@ -78,7 +92,7 @@ var PLUGIN_INFO =
['autoso[urce]', 'aso'],
'Sourcing automatically when the specified file is modified.',
function (arg, bang) {
- (bang ? killWatcher : startWatching)(io.expandPath(arg[0]));
+ (bang ? killWatcher : startWatching)(expandPath(arg[0]));
},
{
bang: true,
--
cgit v1.2.3