aboutsummaryrefslogtreecommitdiff
path: root/vim/after/ftplugin/perl/lint.vim
blob: 86740c8184aadee7f34080b2d87e91980a19fe4b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
" Only do this when not done yet for this buffer
" Also do nothing if 'compatible' enabled
if exists('b:did_ftplugin_perl_lint') || &compatible
  finish
endif
let b:did_ftplugin_perl_lint = 1
if exists('b:undo_ftplugin')
  let b:undo_ftplugin = b:undo_ftplugin
        \ . '|unlet b:did_ftplugin_perl_lint'
endif

" Set up a mapping for the linter, if we're allowed
if !exists('g:no_plugin_maps') && !exists('g:no_perl_maps')

  " Define a mapping target
  nnoremap <buffer> <silent> <unique>
        \ <Plug>PerlLint
        \ :<C-U>write !perlcritic<CR>
  if exists('b:undo_ftplugin')
    let b:undo_ftplugin = b:undo_ftplugin
          \ . '|nunmap <buffer> <Plug>PerlLint'
  endif

  " If there isn't a key mapping already, use a default one
  if !hasmapto('<Plug>PerlLint')
    nmap <buffer> <unique>
          \ <LocalLeader>l
          \ <Plug>PerlLint
    if exists('b:undo_ftplugin')
      let b:undo_ftplugin = b:undo_ftplugin
            \ . '|nunmap <buffer> <LocalLeader>l'
    endif
  endif

endif
class="c1"># which is reloaded each time this file is called. This allows you to quickly # arrange to keep that useful shell function or variable you made inline on # subsequent logins. # # Consider a shell function declared inline with the NAME 'ayy': # # $ ayy() { printf '%s\n' lmao ; } # $ ayy # lmao # $ keep ayy # $ keep # ayy # $ exit # # Then, on next login, the function is redefined for you: # # $ ayy # lmao # # To get rid of it: # # $ keep -d ayy # keep() { # Figure out the directory to which we're reading and writing these scripts local zshkeep zshkeep=${ZSHKEEP:-"$HOME"/.zshkeep.d} mkdir -p -- "$zshkeep" || return # Parse options local opt delete local OPTERR OPTIND OPTARG while getopts 'dh' opt ; do case $opt in # -d given; means delete the keepfiles for the given names d) delete=1 ;; # -h given; means show help h) cat <<EOF ${FUNCNAME[0]}: Keep variables and functions in shell permanently by writing them to named scripts iterated on shell start, in \$ZSHKEEP (defaults to ~/.zshkeep.d). USAGE: ${FUNCNAME[0]} List all the current kept variables and functions ${FUNCNAME[0]} NAME1 [NAME2 ...] Write the current definition for the given NAMEs to keep files ${FUNCNAME[0]} -d NAME1 [NAME2 ...] Delete the keep files for the given NAMEs ${FUNCNAME[0]} -h Show this help EOF return ;; # Unknown other option \?) printf 'zsh: %s -%s: invalid option\n' \ "${FUNCNAME[0]}" "$opt" >&2 return 2 ;; esac done shift "$((OPTIND-1))" # If any arguments left, we must be either keeping or deleting if (($#)) ; then # Start keeping count of any errors local -i errors errors=0 # Iterate through the NAMEs given local name for name ; do # Check NAMEs for validity case $name in # NAME must start with letters or an underscore, and contain no # characters besides letters, numbers, or underscores *[!a-zA-Z0-9_]*|[!a-zA-Z_]*) printf 'zsh: %s: %s not a valid NAME\n' \ "${FUNCNAME[0]}" "$name" >&2 ((errors++)) ;; # NAME is valid, proceed *) # If -d was given, delete the keep files for the NAME if ((delete)) ; then rm -- "$zshkeep"/"$name".zsh || ((errors++)) # Save a function elif [[ $(whence -w "$name") = *': function' ]] ; then declare -f -- "$name" >"$zshkeep"/"$name".zsh || ((errors++)) # Save a variable elif declare -p -- "$name" >/dev/null ; then declare -p -- "$name" >"$zshkeep"/"$name".zsh || ((errors++)) fi ;; esac done # Return 1 if we accrued any errors, 0 otherwise return "$((errors > 0))" fi # Deleting is an error, since we need at least one argument if ((delete)) ; then printf 'zsh: %s: must specify at least one NAME to delete\n' \ "${FUNCNAME[0]}" >&2 return 2 fi # Otherwise the user must want us to print all the NAMEs kept ( declare -a keeps keeps=("$zshkeep"/*.zsh(N)) keeps=("${keeps[@]##*/}") keeps=("${keeps[@]%.zsh}") ((${#keeps[@]})) || exit 0 printf '%s\n' "${keeps[@]}" ) } # Load any existing scripts in zshkeep for zshkeep in "${ZSHKEEP:-"$HOME"/.zshkeep.d}"/*.zsh(N) ; do [[ -e $zshkeep ]] || continue source "$zshkeep" done unset -v zshkeep