aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-06-24 22:57:53 +1200
committerTom Ryder <tom@sanctum.geek.nz>2018-06-24 22:57:53 +1200
commit30696fc63f76f8e3028f2658fd6d55f180133317 (patch)
tree2dfd2bc03a172bfa9b557763c0b2194a9ee3b578
downloadvim-diff-prune-30696fc63f76f8e3028f2658fd6d55f180133317.tar.gz
vim-diff-prune-30696fc63f76f8e3028f2658fd6d55f180133317.zip
Initial versionv0.1.0
-rw-r--r--README.md20
-rw-r--r--VERSION1
-rw-r--r--after/ftplugin/diff/prune.vim49
-rw-r--r--autoload/diff/prune.vim17
-rw-r--r--doc/diff_prune.txt35
5 files changed, 122 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..c8bafe3
--- /dev/null
+++ b/README.md
@@ -0,0 +1,20 @@
+diff\_prune.vim
+===============
+
+This filetype plugin for diffs/patches ("diff" filetype) provides buffer-local
+mappings in normal and visual mode to "undo" lines of changes defined by a
+linewise motion or visual mode selection: leading minus signs are removed, and
+lines with leading plus signs are deleted.
+
+This can be handy for using with the `-e` or `--edit` option to `git-add`,
+which allows you to edit a diff before applying changes to the staging area.
+
+The default binding is `<LocalLeader>p`.
+
+License
+-------
+
+Copyright (c) [Tom Ryder][1]. Distributed under the same terms as Vim itself.
+See `:help license`.
+
+[1]: https://sanctum.geek.nz/
diff --git a/VERSION b/VERSION
new file mode 100644
index 0000000..6e8bf73
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+0.1.0
diff --git a/after/ftplugin/diff/prune.vim b/after/ftplugin/diff/prune.vim
new file mode 100644
index 0000000..49bc50f
--- /dev/null
+++ b/after/ftplugin/diff/prune.vim
@@ -0,0 +1,49 @@
+" diff/prune.vim: Provide a mapping to remove blocks of a diff buffer.
+
+" Don't load if running compatible or too old
+if &compatible || v:version < 700
+ finish
+endif
+
+" Don't load if already loaded
+if exists('b:did_ftplugin_diff_prune')
+ finish
+endif
+
+" Stop here if the user doesn't want ftplugin mappings
+if exists('g:no_plugin_maps') || exists('g:no_diff_maps')
+ finish
+endif
+
+" Flag as loaded
+let b:did_ftplugin_diff_prune = 1
+let b:undo_ftplugin = b:undo_ftplugin
+ \ . '|unlet b:did_ftplugin_diff_prune'
+
+" Define normal mode mapping target
+nnoremap <buffer> <silent>
+ \ <Plug>DiffPrune
+ \ :<C-U>set operatorfunc=diff#prune#Prune<CR>g@
+let b:undo_ftplugin = b:undo_ftplugin
+ \ . '|nunmap <buffer> <Plug>DiffPrune'
+
+" Default local normal mapping if not already defined
+if !hasmapto('<Plug>DiffPrune', 'n')
+ nmap <buffer> <LocalLeader>p <Plug>DiffPrune
+ let b:undo_ftplugin = b:undo_ftplugin
+ \ . '|nunmap <buffer> <LocalLeader>p'
+endif
+
+" Define visual mode mapping target
+vnoremap <buffer> <silent>
+ \ <Plug>DiffPrune
+ \ :<C-U>call diff#prune#Prune(visualmode())<CR>
+let b:undo_ftplugin = b:undo_ftplugin
+ \ . '|vunmap <buffer> <Plug>DiffPrune'
+
+" Default local normal mapping if not already defined
+if !hasmapto('<Plug>DiffPrune', 'v')
+ vmap <buffer> <LocalLeader>p <Plug>DiffPrune
+ let b:undo_ftplugin = b:undo_ftplugin
+ \ . '|vunmap <buffer> <LocalLeader>p'
+endif
diff --git a/autoload/diff/prune.vim b/autoload/diff/prune.vim
new file mode 100644
index 0000000..cb4f410
--- /dev/null
+++ b/autoload/diff/prune.vim
@@ -0,0 +1,17 @@
+" Undo some diff lines
+function diff#prune#Prune(type) abort
+
+ " Choose appropriate line ranges depending on mode
+ if a:type =~# "^[vV\<C-V>]$"
+ let l:range = '''<,''>'
+ else
+ let l:range = '''[,'']'
+ endif
+
+ " Reinstate removals and remove addenda; preserve search pattern
+ let l:search_save = @/
+ silent execute l:range.'substitute/^-/ /e'
+ silent execute l:range.'global/^+/d'
+ let @/ = l:search_save
+
+endfunction
diff --git a/doc/diff_prune.txt b/doc/diff_prune.txt
new file mode 100644
index 0000000..88ace86
--- /dev/null
+++ b/doc/diff_prune.txt
@@ -0,0 +1,35 @@
+*diff_prune.txt* For Vim version 7.0 Last change: 2018 June 24
+
+DESCRIPTION *diff_prune*
+
+This filetype plugin for diffs/patches ("diff" filetype) provides buffer-local
+mappings in normal and visual mode to reverse changes defined by a linewise
+motion or visual mode selection: leading minus signs are removed, and lines
+with leading plus signs are deleted.
+
+This can be handy for using with the `-e` or `--edit` option to `git-add`,
+which allows you to edit a diff before applying changes to the staging area.
+
+REQUIREMENTS *diff_prune-requirements*
+
+This plugin is only available if 'compatible' is not set. It requires Vim 7.0
+or newer.
+
+MAPPINGS *diff_prune-mappings*
+ *<Plug>DiffPrune*
+
+A single mapping target name for two mods |<Plug>DiffPrune| is provided.
+
+If the user's configuration does not specify a mapping to this target by the
+time this plugin is loaded, the plugin will attempt to remap normal and visual
+`<LocalLeader>p` to this target.
+
+AUTHOR *diff_prune-author*
+
+Written and maintained by Tom Ryder <tom@sanctum.geek.nz>.
+
+LICENSE *diff_prune-license*
+
+Licensed for distribution under the same terms as Vim itself (see |license|).
+
+ vim:tw=78:ts=8:ft=help:norl: