Commits

Takeshi NISHIDA  committed 343ae98

refactored

  • Participants
  • Parent commits 7804246

Comments (0)

Files changed (5)

File autoload/sfe.vim

 
 " }}}1
 "=============================================================================
-" PUBLIC: sfe#execute*: {{{1
+" GLOBAL FUNCTIONS {{{1
 
 "
-function sfe#executeCommand(boolAlt, cwd)
-  let impl = s:createImplementor(a:boolAlt, a:cwd, 1)
-  if !impl.isValid() || !s:warnIfUnsavedBufferExist(0)
+function sfe#launch(commandName, anotherScm, cwd, confirmingUnsaved)
+  let impl = s:createImplementor(a:anotherScm, a:cwd, 1)
+  if !impl.isValid() || !s:warnIfUnsavedBufferExist(a:confirmingUnsaved)
     return
   endif
-  call impl.command()
-endfunction
-
-"
-function sfe#executeCommitFile(boolAlt, cwd)
-  let impl = s:createImplementor(a:boolAlt, a:cwd, 1)
-  if !impl.isValid() || !s:warnIfUnsavedBufferExist(1)
-    return
-  endif
-  call impl.commitFile()
-endfunction
-
-"
-function sfe#executeCommitTracked(boolAlt, cwd)
-  let impl = s:createImplementor(a:boolAlt, a:cwd, 1)
-  if !impl.isValid() || !s:warnIfUnsavedBufferExist(1)
-    return
-  endif
-  call impl.commitTracked()
-endfunction
-
-"
-function sfe#executeCommitAll(boolAlt, cwd)
-  let impl = s:createImplementor(a:boolAlt, a:cwd, 1)
-  if !impl.isValid() || !s:warnIfUnsavedBufferExist(1)
-    return
-  endif
-  call impl.commitAll()
-endfunction
-
-"
-function sfe#executeRecordFile(boolAlt, cwd)
-  let impl = s:createImplementor(a:boolAlt, a:cwd, 1)
-  if !impl.isValid() || !s:warnIfUnsavedBufferExist(1)
-    return
-  endif
-  call impl.recordFile()
-endfunction
-
-"
-function sfe#executeRecordAll(boolAlt, cwd)
-  let impl = s:createImplementor(a:boolAlt, a:cwd, 1)
-  if !impl.isValid() || !s:warnIfUnsavedBufferExist(1)
-    return
-  endif
-  call impl.recordAll()
-endfunction
-
-"
-function sfe#executeCheckout(boolAlt, cwd)
-  let impl = s:createImplementor(a:boolAlt, a:cwd, 1)
-  if !impl.isValid() || !s:warnIfUnsavedBufferExist(1)
-    return
-  endif
-  call impl.checkout()
+  let methodName = tolower(a:commandName[0]) . a:commandName[1:]
+  call impl[methodName]()
   call sfe#invalidateStatusReport(a:cwd)
 endfunction
 
-"
-function sfe#executeMerge(boolAlt, cwd)
-  let impl = s:createImplementor(a:boolAlt, a:cwd, 1)
-  if !impl.isValid() || !s:warnIfUnsavedBufferExist(1)
-    return
-  endif
-  call impl.merge()
-  call sfe#invalidateStatusReport(a:cwd)
-endfunction
-
-"
-function sfe#executeBranch(boolAlt, cwd)
-  let impl = s:createImplementor(a:boolAlt, a:cwd, 1)
-  if !impl.isValid() || !s:warnIfUnsavedBufferExist(1)
-    return
-  endif
-  call impl.branch()
-  call sfe#invalidateStatusReport(a:cwd)
-endfunction
-
-"
-function sfe#executeBranchDelete(boolAlt, cwd)
-  let impl = s:createImplementor(a:boolAlt, a:cwd, 1)
-  if !impl.isValid() || !s:warnIfUnsavedBufferExist(1)
-    return
-  endif
-  call impl.branchDelete()
-  call sfe#invalidateStatusReport(a:cwd)
-endfunction
-
-"
-function sfe#executeRebase(boolAlt, cwd)
-  let impl = s:createImplementor(a:boolAlt, a:cwd, 1)
-  if !impl.isValid() || !s:warnIfUnsavedBufferExist(1)
-    return
-  endif
-  call impl.rebase()
-endfunction
-
-"
-function sfe#executeStrip(boolAlt, cwd)
-  let impl = s:createImplementor(a:boolAlt, a:cwd, 1)
-  if !impl.isValid() || !s:warnIfUnsavedBufferExist(1)
-    return
-  endif
-  call impl.strip()
-endfunction
-
-"
-function sfe#executePull(boolAlt, cwd)
-  let impl = s:createImplementor(a:boolAlt, a:cwd, 1)
-  if !impl.isValid() || !s:warnIfUnsavedBufferExist(1)
-    return
-  endif
-  call impl.pull()
-endfunction
-
-"
-function sfe#executePush(boolAlt, cwd)
-  let impl = s:createImplementor(a:boolAlt, a:cwd, 1)
-  if !impl.isValid() || !s:warnIfUnsavedBufferExist(1)
-    return
-  endif
-  call impl.push()
-endfunction
-
-"
-function sfe#executeDiffFile(boolAlt, cwd)
-  let impl = s:createImplementor(a:boolAlt, a:cwd, 1)
-  if !impl.isValid()
-    return
-  endif
-  call impl.diffFile()
-endfunction
-
-"
-function sfe#executeDiffAll(boolAlt, cwd)
-  let impl = s:createImplementor(a:boolAlt, a:cwd, 1)
-  if !impl.isValid() || !s:warnIfUnsavedBufferExist(0)
-    return
-  endif
-  call impl.diffAll()
-endfunction
-
-"
-function sfe#executeLogFile(boolAlt, cwd)
-  let impl = s:createImplementor(a:boolAlt, a:cwd, 1)
-  if !impl.isValid()
-    return
-  endif
-  call impl.logFile()
-endfunction
-
-"
-function sfe#executeLogAll(boolAlt, cwd)
-  let impl = s:createImplementor(a:boolAlt, a:cwd, 1)
-  if !impl.isValid()
-    return
-  endif
-  call impl.logAll()
-endfunction
-
-"
-function sfe#executeAnnotateFile(boolAlt, cwd)
-  let impl = s:createImplementor(a:boolAlt, a:cwd, 1)
-  if !impl.isValid()
-    return
-  endif
-  call impl.annotateFile()
-endfunction
-
-"
-function sfe#executeStatus(boolAlt, cwd)
-  let impl = s:createImplementor(a:boolAlt, a:cwd, 1)
-  if !impl.isValid() || !s:warnIfUnsavedBufferExist(0)
-    return
-  endif
-  call impl.status()
-endfunction
-
-"
-function sfe#executeGrep(boolAlt, cwd)
-  let impl = s:createImplementor(a:boolAlt, a:cwd, 1)
-  if !impl.isValid() || !s:warnIfUnsavedBufferExist(0)
-    return
-  endif
-  call impl.grep()
-endfunction
-
-"
-function sfe#executeLoadModified(boolAlt, cwd)
-  let impl = s:createImplementor(a:boolAlt, a:cwd, 1)
-  if !impl.isValid() || !s:warnIfUnsavedBufferExist(0)
-    return
-  endif
-  call impl.loadModified()
-endfunction
-
-"
-function sfe#executeLoadAll(boolAlt, cwd)
-  let impl = s:createImplementor(a:boolAlt, a:cwd, 1)
-  if !impl.isValid() || !s:warnIfUnsavedBufferExist(0)
-    return
-  endif
-  call impl.loadAll()
-endfunction
-
-"
-function sfe#executeFindFile(boolAlt, cwd)
-  let impl = s:createImplementor(a:boolAlt, a:cwd, 1)
-  if !impl.isValid() || !s:warnIfUnsavedBufferExist(0)
-    return
-  endif
-  call impl.findFile()
-endfunction
-
-" }}}1
-"=============================================================================
-" PUBLIC: UTILITY FUNCTIONS: {{{1
-
 " gets target file path associated with current buffer
 function sfe#getTargetFile()
   return (exists('b:sfe_targetFile') ? b:sfe_targetFile : expand('%:p'))
 
 " }}}1
 "=============================================================================
-" UTILITY FUNCTIONS: {{{1
+" LOCAL FUNCTIONS/VARIABLES {{{1
 
 "
 function s:formatCommitBufferLines(nameScm, dirRoot, nameBranch, linesStatus, linesDiff)
 
 
 " 
-function s:createImplementor(boolAlt, cwd, boolEchoError)
+function s:createImplementor(anotherScm, cwd, echoingError)
   let impls = s:createAvailableImplementors(a:cwd)
   if !empty(impls)
-    return impls[a:boolAlt ? -1 : 0]
+    return impls[a:anotherScm ? -1 : 0]
   endif
-  if a:boolEchoError
+  if a:echoingError
     call sfe#echoError('There is no available repository: ' . sfe#escapeForShell(a:cwd))
   endif
   return s:implementorBase
 endfunction
 
 "
-function s:warnIfUnsavedBufferExist(boolAsk)
+function s:warnIfUnsavedBufferExist(confirming)
   if empty(filter(range(1, bufnr('$')), 's:isModifiedBuffer(v:val)'))
     return 1
   endif
-  if !a:boolAsk
+  if !a:confirming
     call sfe#echoWarning('Unsaved buffers exist.')
     return 1
   endif
 
 " }}}1
 "=============================================================================
-" implementorBase: {{{1
+" s:implementorBase {{{1
 
 let s:implementorBase = {}
 
 
 " }}}1
 "=============================================================================
-" s:commitBufferLister: {{{1
+" s:commitBufferLister {{{1
 
 "
 let s:commitBufferLister = {}
 
 " }}}1
 "=============================================================================
-" s:recordBufferLister: {{{1
+" s:recordBufferLister {{{1
 
 "
 let s:recordBufferLister = {}

File autoload/sfe/bazaar.vim

 
 " }}}1
 "=============================================================================
-" PUBLIC: {{{1
+" GLOBAL FUNCTIONS {{{1
 
 " if a:cwd is not in repository, returns {}
 function sfe#bazaar#createImplementor(cwd)
 
 " }}}1
 "=============================================================================
-" UTILITY FUNCTIONS: {{{1
+" LOCAL FUNCTIONS/VARIABLES {{{1
 
 "
 function s:formatStatusLine(line)
 
 " }}}1
 "=============================================================================
-" implementor: {{{1
+" implementor {{{1
 
 let s:implementor = {}
 

File autoload/sfe/git.vim

 
 " }}}1
 "=============================================================================
-" PUBLIC: {{{1
+" GLOBAL FUNCTIONS {{{1
 
 " if a:cwd is not in repository, returns {}
 function sfe#git#createImplementor(cwd)
 
 " }}}1
 "=============================================================================
-" UTILITY FUNCTIONS: {{{1
+" LOCAL FUNCTIONS/VARIABLES {{{1
 
 "
 function s:formatStatusLine(line)
 
 " }}}1
 "=============================================================================
-" implementor: {{{1
+" implementor {{{1
 
 let s:implementor = {}
 
 
 "
 function s:implementor.executeMerge(revision)
-  call sfe#echoMessage(self.execute(['merge', sfe#escapeForShell(a:revision)]))
+  call self.executeByShell(['merge', sfe#escapeForShell(a:revision)])
 endfunction
 
 "

File autoload/sfe/mercurial.vim

 
 " }}}1
 "=============================================================================
-" PUBLIC: {{{1
+" GLOBAL FUNCTIONS {{{1
 
 " if a:cwd is not in repository, returns {}
 function sfe#mercurial#createImplementor(cwd)
 
 " }}}1
 "=============================================================================
-" UTILITY FUNCTIONS: {{{1
+" LOCAL FUNCTIONS/VARIABLES {{{1
 
 "
 function s:formatStatusLine(line)
 
 " }}}1
 "=============================================================================
-" implementor: {{{1
+" implementor {{{1
 
 let s:implementor = {}
 
 
 "
 function s:implementor.executeMerge(revision)
-  call sfe#echoMessage(self.execute(['merge -v -r', sfe#escapeForShell(a:revision)]))
+  call self.executeByShell(['merge -v -r', sfe#escapeForShell(a:revision)])
 endfunction
 
 "

File plugin/sfe.vim

 " LOCAL FUNCTION: {{{1
 
 "
-function s:getNames()
-  return [
-        \   'Command'      ,
-        \   'CommitFile'   ,
-        \   'CommitTracked',
-        \   'CommitAll'    ,
-        \   'RecordFile'   ,
-        \   'RecordAll'    ,
-        \   'Checkout'     ,
-        \   'Merge'        ,
-        \   'Branch'       ,
-        \   'BranchDelete' ,
-        \   'Rebase'       ,
-        \   'Strip'        ,
-        \   'Pull'         ,
-        \   'Push'         ,
-        \   'DiffFile'     ,
-        \   'DiffAll'      ,
-        \   'LogFile'      ,
-        \   'LogAll'       ,
-        \   'AnnotateFile' ,
-        \   'Status'       ,
-        \   'Grep'         ,
-        \   'LoadModified' ,
-        \   'LoadAll'      ,
-        \   'FindFile'     ,
+function s:initialize()
+  "---------------------------------------------------------------------------
+  let commandData = [
+        \   ['Command'      , 0],
+        \   ['CommitFile'   , 1],
+        \   ['CommitTracked', 1],
+        \   ['CommitAll'    , 1],
+        \   ['RecordFile'   , 1],
+        \   ['RecordAll'    , 1],
+        \   ['Checkout'     , 1],
+        \   ['Merge'        , 1],
+        \   ['Branch'       , 1],
+        \   ['BranchDelete' , 1],
+        \   ['Rebase'       , 1],
+        \   ['Strip'        , 1],
+        \   ['Pull'         , 1],
+        \   ['Push'         , 1],
+        \   ['DiffFile'     , 0],
+        \   ['DiffAll'      , 0],
+        \   ['LogFile'      , 0],
+        \   ['LogAll'       , 0],
+        \   ['AnnotateFile' , 0],
+        \   ['Status'       , 0],
+        \   ['Grep'         , 0],
+        \   ['LoadModified' , 0],
+        \   ['LoadAll'      , 0],
+        \   ['FindFile'     , 0],
         \ ]
-endfunction
-
-"
-function s:initOptons()
+  "---------------------------------------------------------------------------
   call l9#defineVariableDefault('g:sfe_availableScms',
         \ filter(['mercurial', 'git', 'bazaar'], 'sfe#{v:val}#isExecutable()'))
   call l9#defineVariableDefault('g:sfe_mapLeader', '\s')
   call l9#defineVariableDefault('g:sfe_hgLogOption', '-l1000 --style compact')
   call l9#defineVariableDefault('g:sfe_gitLogOption', '-1000 --all --graph --pretty=format:''%h (%ci) %s''')
   call l9#defineVariableDefault('g:sfe_bzrLogOption', '-l1000 --line')
-endfunction
-
-"
-function s:initCommands()
-  for name in s:getNames()
-    execute printf('command! -bang %s call %s(%s)',
-          \        'Sfe' . name,
-          \        'sfe#execute' . name,
-          \        'len(<q-bang>), sfe#getTargetDir()')
+  "---------------------------------------------------------------------------
+  for [commandName, confirmingUnsaved] in commandData
+    execute printf('command! -bang %s call sfe#launch(%s, len(<q-bang>), sfe#getTargetDir(), %d)',
+          \        'Sfe' . commandName, string(commandName), confirmingUnsaved)
   endfor
-endfunction
-
-"
-function s:initMappings()
+  "---------------------------------------------------------------------------
   for [leader, bang] in [ [g:sfe_mapLeader, ''], [g:sfe_mapLeaderAlternate, '!'] ]
     execute printf('nnoremap <silent> %s      <Nop>', leader)
     execute printf('nnoremap <silent> %s<Esc> <Nop>', leader)
-    for name in s:getNames()
+    for [commandName, confirmingUnsaved] in commandData
       execute printf('nnoremap <silent> %s :%s%s<CR>',
-            \        leader . g:sfe_mapKey{name},
-            \        'Sfe' . name,
+            \        leader . g:sfe_mapKey{commandName},
+            \        'Sfe' . commandName,
             \        bang)
     endfor
   endfor
-endfunction
-
-"
-function s:initAutoCommands()
+  "---------------------------------------------------------------------------
   augroup SfeGlobal
     autocmd!
     autocmd CursorHold   * call sfe#invalidateStatusReport(sfe#getTargetDir())
     autocmd CursorHoldI  * call sfe#invalidateStatusReport(sfe#getTargetDir())
     "autocmd BufWritePost * call sfe#invalidateStatusReport(sfe#getTargetDir())
   augroup END
+  "---------------------------------------------------------------------------
 endfunction
 
 " }}}1
 "=============================================================================
 " INITIALIZATION: {{{1
 
-call s:initOptons()
-call s:initCommands()
-call s:initMappings()
-call s:initAutoCommands()
+call s:initialize()
 
 " }}}1
 "=============================================================================