aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md14
-rw-r--r--VERSION1
-rw-r--r--after/ftplugin/make/target.vim29
-rw-r--r--autoload/make/target.vim32
-rw-r--r--doc/make_target.txt55
5 files changed, 131 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..61061b8
--- /dev/null
+++ b/README.md
@@ -0,0 +1,14 @@
+make\_target.vim
+================
+
+This filetype plugin for Makefiles ("make" filetype) provides an autoload
+function `make#target#Make()` and buffer-local mapping `<Plug>MakeTarget` to
+`make!` the target for the recipe under the cursor, if it can be identified.
+
+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/make/target.vim b/after/ftplugin/make/target.vim
new file mode 100644
index 0000000..dc1663a
--- /dev/null
+++ b/after/ftplugin/make/target.vim
@@ -0,0 +1,29 @@
+" make/target.vim: Provide a mapping to :make the target for the recipe under
+" the cursor.
+
+" 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_make_target')
+ finish
+endif
+
+" Stop here if the user doesn't want ftplugin mappings
+if exists('g:no_plugin_maps') || exists('g:no_make_maps')
+ finish
+endif
+
+" Flag as loaded
+let b:did_ftplugin_make_target = 1
+let b:undo_ftplugin = b:undo_ftplugin
+ \ . '|unlet b:did_ftplugin_make_target'
+
+" Define normal mode mapping target
+nnoremap <buffer> <silent> <unique>
+ \ <Plug>MakeTarget
+ \ :<C-U>call make#target#Make()<CR>
+let b:undo_ftplugin = b:undo_ftplugin
+ \ . '|nunmap <buffer> <Plug>MakeTarget'
diff --git a/autoload/make/target.vim b/autoload/make/target.vim
new file mode 100644
index 0000000..e3c0861
--- /dev/null
+++ b/autoload/make/target.vim
@@ -0,0 +1,32 @@
+" Function to make the target for the recipe under the cursor
+function! make#target#Make() abort
+
+ " Declare list of targets to build
+ let l:targets = []
+
+ " Iterate back through the file starting at the current line looking for the
+ " line with the target
+ for l:li in reverse(range(1, line('.')))
+ let l:line = getline(l:li)
+
+ " If it matches the target format, we've found our line; split the targets
+ " by space, and break
+ let l:matchlist = matchlist(l:line, '^\([^:= \t][^:=]*\):')
+ if len(l:matchlist)
+ let l:targets = split(l:matchlist[1], '\s\+')
+ break
+
+ " If it wasn't the target line and doesn't have leading tabs, we're not in
+ " a recipe block; break with an unset target
+ elseif strpart(l:line, 0, 1) !=# "\t"
+ break
+ endif
+
+ endfor
+
+ " If we found targets, :make them
+ for l:target in l:targets
+ execute 'make! '.l:target
+ endfor
+
+endfunction
diff --git a/doc/make_target.txt b/doc/make_target.txt
new file mode 100644
index 0000000..65078ea
--- /dev/null
+++ b/doc/make_target.txt
@@ -0,0 +1,55 @@
+*make_target.txt* For Vim version 7.0 Last change: 2018 June 28
+
+DESCRIPTION *make_target*
+
+This filetype plugin for Makefiles ("make" filetype) provides an autoload
+function `make#target#Make()` and buffer-local mapping `<Plug>MakeTarget` to
+`make!` the target for the recipe under the cursor, if it can be identified.
+
+REQUIREMENTS *make_target-requirements*
+
+This plugin is only available if 'compatible' is not set. It requires Vim 7.0
+or newer. It won't load at all if you have `g:no_plugin_maps` or
+`g:no_make_maps` set.
+
+MAPPINGS *make_target-mappings*
+
+ *<Plug>MakeTarget*
+The |map-local| mapping `<Plug>MakeTarget` attempts to identify the target or
+targets for the recipe under the cursor, and runs `make!` in sequence on each
+of those targets.
+
+There is no default key binding; you could do this in your `.vimrc` to bind
+`_m`, for example:
+>
+ autocmd FileType make
+ \ nmap <buffer> _m <Plug>MakeTarget
+<
+A cleaner and more complete implementation that correctly clears the group on
+reload and the mapping on filetype switch might be:
+>
+ let g:maplocalleader = '_'
+ augroup vimrc_filemap
+ autocmd!
+ autocmd FileType *
+ \ silent! nmapclear <buffer> <LocalLeader>m
+ autocmd FileType make
+ \ nmap <buffer> <LocalLeader>m <Plug>MakeTarget
+ augroup END
+<
+FUNCTIONS *make_target-functions*
+
+ *make#target#Make()*
+The |autoload| function used by |<Plug>MakeTarget| is accessible as
+`make#target#Make()` if wanted. It's hardcoded to look for the target under
+the cursor.
+
+AUTHOR *make_target-author*
+
+Written and maintained by Tom Ryder <tom@sanctum.geek.nz>.
+
+LICENSE *make_target-license*
+
+Licensed for distribution under the same terms as Vim itself (see |license|).
+
+ vim:tw=78:ts=8:ft=help:norl: