Commits

ZyX_I  committed 49b075f

Add PrevMod/NextMod mappings to aurum://file and aurum://annotate

Fixes #90

Requires tests

  • Participants
  • Parent commits eef9912

Comments (0)

Files changed (4)

File autoload/aurum/file.vim

 "▶1 
 scriptencoding utf-8
 execute frawor#Setup('0.2', {'@%aurum/cmdutils': '4.3',
-            \                '@%aurum/maputils': '0.1',
+            \                '@%aurum/maputils': '0.2',
             \                 '@%aurum/bufvars': '0.0',
             \               '@%aurum/lineutils': '0.0',
             \                 '@%aurum/vimdiff': '1.0',
 call s:_f.newcommand(s:file)
 unlet s:file
 "▶1 aurum://file mappings
-function s:F.runmap(action)
+function s:F.runmap(action, ...)
     let buf=bufnr('%')
     let bvar=s:_r.bufvars[buf]
     if a:action is# 'exit'
     elseif a:action is# 'previous' || a:action is# 'next'
         let c=((a:action is# 'previous')?(v:count1):(-v:count1))
         let [rev, file]=s:_r.maputils.getnthparentfile(bvar.repo, bvar.rev,
-                    \                                  bvar.file, c)
+                    \                                  bvar.file, c,
+                    \                                  get(a:000, 0, 1))
         let bhwipe=(&bufhidden is# 'wipe')
         if has_key(bvar, 'preserve')
             let d={'restore': bvar.preserve()}
 call s:_f.mapgroup.add('AuFile', {
             \   'Next': {'lhs':  'K', 'rhs': s:m('next'          )},
             \   'Prev': {'lhs':  'J', 'rhs': s:m('previous'      )},
+            \'NextMod': {'lhs': 'gK', 'rhs': s:m('next'    , 0   )},
+            \'PrevMod': {'lhs': 'gJ', 'rhs': s:m('previous', 0   )},
             \ 'Update': {'lhs':  'U', 'rhs': s:m('update'        )},
             \   'Exit': {'lhs':  'X', 'rhs': s:m('exit'          )},
             \   'Diff': {'lhs':  'd', 'rhs': s:m(          'diff')},

File autoload/aurum/maputils.vim

 "▶1
 scriptencoding utf-8
-execute frawor#Setup('0.1', {'@/resources': '0.0',
+execute frawor#Setup('0.2', {'@/resources': '0.0',
             \                       '@/os': '0.0',})
 let s:_messages={
             \'plinst': 'If you install Command-T, Ctrlp, FuzzyFinder, unite, '.
 function s:r.readfilewrapper(file, repo, rev)
     return a:repo.functions.readfile(a:repo, a:rev, a:file)
 endfunction
-"▶1 getnthparentfile :: repo, rev, file, n → (hex, file)
-function s:r.getnthparentfile(repo, rev, file, n)
+"▶1 getnthparentfile :: repo, rev, file, n[, changedonly] → (hex, file)
+function s:r.getnthparentfile(repo, rev, file, n, ...)
     let n=a:n
     let shift=(n>0 ? 1 : -1)
     let file=a:file
+    let prevhex=0
     let hex=a:repo.functions.getrevhex(a:repo, a:rev)
-    while n
+    while n && hex isnot# prevhex
+        let prevhex=hex
         let cs=a:repo.functions.getnthparent(a:repo, hex, shift)
         let rhex=(shift>0 ? hex : cs.hex)
         if cs.hex is# hex
             call map(copy(renames), 'extend(rrenames, {v:val : v:key})')
             let renames=rrenames
         endif
+        let haschanges=get(a:000, 0, 1)
         if get(renames, file, 0) isnot 0
             let file=renames[file]
+            let haschanges=1
+        elseif !haschanges
+            let status=a:repo.functions.status(a:repo, prevhex, hex, [a:file])
+            let haschanges=!empty(filter(copy(status),
+                        \              'v:key isnot# "clean" && !empty(v:val)'))
         endif
-        let n-=shift
+        if haschanges
+            let n-=shift
+        endif
     endwhile
     return [hex, file]
 endfunction

File doc/aurum.txt

              *g:frawormap_AuAnnotate_Diff*   *g:frawormap_AuAnnotate_RFVdiff*
              *g:frawormap_AuAnnotate_Rdiff*  *g:frawormap_AuAnnotate_Annotate*
              *g:frawormap_AuAnnotate_RVdiff* *g:frawormap_AuAnnotate_Open*
-             *g:frawormap_AuAnnotate_Update* *g:frawormap_AuAnnotate_Next*
+             *g:frawormap_AuAnnotate_Update* *g:frawormap_AuAnnotate_NextMod*
+             *g:frawormap_AuAnnotate_Next*   *g:frawormap_AuAnnotate_PrevMod*
              *g:frawormap_AuAnnotate_Prev*       *aurum-m-AuAnnotate_Prev*
                  *aurum-m-AuAnnotate_Enter*      *aurum-m-AuAnnotate_Fdiff*
                  *aurum-m-AuAnnotate_RFdiff*     *aurum-m-AuAnnotate_FVdiff*
                  *aurum-m-AuAnnotate_Diff*       *aurum-m-AuAnnotate_RFVdiff*
                  *aurum-m-AuAnnotate_Rdiff*      *aurum-m-AuAnnotate_Annotate*
                  *aurum-m-AuAnnotate_RVdiff*     *aurum-m-AuAnnotate_Open*
-                 *aurum-m-AuAnnotate_Update*     *aurum-m-AuAnnotate_Next*
+                 *aurum-m-AuAnnotate_Update*     *aurum-m-AuAnnotate_NextMod*
+                 *aurum-m-AuAnnotate_Next*       *aurum-m-AuAnnotate_PrevMod*
     Mapname  LHS  Description ~
     Enter    <CR> View changes between file and current revision (|vimdiff|)
     FVdiff   gD   View diff between working directory and current revision 
     Prev      J   Reannotate file using first parent of annotated revision.
                   Accepts count, in this case first parent is taken {count} 
                   times ({count}=2: first parent of first parent)
+    NextMod  gK   Like above Next mapping, but children are taken until it 
+                  does not find revision where file was changed. {count}=2 
+                  means two changes after, not two children before.
+    PrevMod  gJ   Like above Prev mapping, but parents are taken until it does 
+                  not find revision where file was changed. {count}=2 means 
+                  two changes before, not two parents before.
 
     Note These mappings are defined for aurumannotate filetype.
 
     Open file {file} from repository {repo} as it was at revision {rev}.
     Local mappings (mgid=AuFile, without leader by default):
                                                           *g:frawormap_AuFile*
-                       *g:frawormap_AuFile_Next*  *g:frawormap_AuFile_RFdiff*
-                       *g:frawormap_AuFile_Prev*  *g:frawormap_AuFile_RFVdiff*
-                       *g:frawormap_AuFile_Diff*  *g:frawormap_AuFile_Update*
-                       *g:frawormap_AuFile_Rdiff* *g:frawormap_AuFile_RVdiff*
-                       *g:frawormap_AuFile_Fdiff* *g:frawormap_AuFile_FVdiff*
-                       *g:frawormap_AuFile_Vdiff*     *aurum-m-AuFile_Vdiff*
-                           *aurum-m-AuFile_Next*      *aurum-m-AuFile_RFdiff*
-                           *aurum-m-AuFile_Prev*      *aurum-m-AuFile_RFVdiff*
-                           *aurum-m-AuFile_Rdiff*     *aurum-m-AuFile_RVdiff*
-                           *aurum-m-AuFile_Diff*      *aurum-m-AuFile_Update*
-                           *aurum-m-AuFile_Fdiff*     *aurum-m-AuFile_FVdiff*
+                    *g:frawormap_AuFile_Next*     *g:frawormap_AuFile_RFdiff*
+                    *g:frawormap_AuFile_Prev*     *g:frawormap_AuFile_RFVdiff*
+                    *g:frawormap_AuFile_Diff*     *g:frawormap_AuFile_Update*
+                    *g:frawormap_AuFile_Rdiff*    *g:frawormap_AuFile_RVdiff*
+                    *g:frawormap_AuFile_Fdiff*    *g:frawormap_AuFile_FVdiff*
+                    *g:frawormap_AuFile_NextMod*  *g:frawormap_AuFile_PrevMod*
+                    *g:frawormap_AuFile_Vdiff*        *aurum-m-AuFile_Vdiff*
+                        *aurum-m-AuFile_Next*         *aurum-m-AuFile_RFdiff*
+                        *aurum-m-AuFile_Prev*         *aurum-m-AuFile_RFVdiff*
+                        *aurum-m-AuFile_Rdiff*        *aurum-m-AuFile_RVdiff*
+                        *aurum-m-AuFile_Diff*         *aurum-m-AuFile_Update*
+                        *aurum-m-AuFile_Fdiff*        *aurum-m-AuFile_FVdiff*
+                        *aurum-m-AuFile_NextMod*      *aurum-m-AuFile_PrevMod*
     Mapname  LHS  Description ~
     Next      K   View current file as it was at first child of current 
                   revision. Accepts count, in this case first child is taken 
     Prev      J   View current file as it was at first parent of current 
                   revision. Accepts count, in this case first parent is taken 
                   {count} times ({count}=2: first parent of first parent)
+    NextMod  gK   Like above Next mapping, but children are taken until it 
+                  does not find revision where file was changed. {count}=2 
+                  means two changes after, not two children before.
+    PrevMod  gJ   Like above Prev mapping, but parents are taken until it does 
+                  not find revision where file was changed. {count}=2 means 
+                  two changes before, not two parents before.
     Update    U   Update working directory to current revision.
                   Accepts count: {count}=3: update to first parent of first 
                   parent of current revision
                            (status: between two current revisions)
 Rdiff       c   a  fls     Shows changes done in current rev to current file
 Prev/Next  J/K  acdfl      Go to previous/next revision
+PrevMod    gJ   a  f       Go to previous revision where file was modified
+NextMod    gK   a  f       Go to next revision where file was modified
 Open        o   a d ls  g  Opens current file as it was at current revision
 OpenAny     O       l   g  Prompts user and opens one of the changeset files
 Annotate    a   a   ls  g  Annotates current file at current revision
     0.1: Added support for password in URL.
 @%aurum/maputils:
     0.1: Added _r.maputils.getnthparentfile().
+    0.2: Added optional argument to _r.maputils.getnthparentfile().
 @%aurum/record:
     0.1: Added |:AuRecord| amend.
 

File ftplugin/aurumannotate.vim

     elseif a:action is# 'previous' || a:action is# 'next'
         let c=((a:action is# 'previous')?(v:count1):(-v:count1))
         let [rev, file]=s:_r.maputils.getnthparentfile(bvar.repo, bvar.rev,
-                    \                                  bvar.file, c)
+                    \                                  bvar.file, c,
+                    \                                  get(a:000, 0, 1))
         if rev is# bvar.rev
             call s:_f.throw('no'.a:action[:3], bvar.rev)
         endif
             \   'Update': {'lhs':  'U',   'rhs': s:F.getrhs(    'update'   )},
             \     'Next': {'lhs':  'K',   'rhs': s:F.getrhs('next'         )},
             \     'Prev': {'lhs':  'J',   'rhs': s:F.getrhs('previous'     )},
+            \  'NextMod': {'lhs': 'gK',   'rhs': s:F.getrhs('next'      , 0)},
+            \  'PrevMod': {'lhs': 'gJ',   'rhs': s:F.getrhs('previous'  , 0)},
             \     'Exit': {'lhs':  'X',   'rhs': ':<C-u>bwipeout!<CR>'      },
             \}, {'silent': 1, 'mode': 'n'})
 "▶1