From aebe193136719f9004a9a753c074d96cc4076e93 Mon Sep 17 00:00:00 2001 From: cornfeedhobo Date: Fri, 5 Feb 2021 00:15:02 -0600 Subject: [PATCH] Squashed 'vendor/github.com/erichs/composure/' changes from 5c3698d..55fdb9f 55fdb9f Merge pull request #24 from bvberkum/pr-21 b360ca5 Use command name, not last argument as shell-name [#23] 5c458c9 22 - Document revise behavior with GUI editors 7de4304 Update LICENSE copyright f784e3a Merge pull request #20 from akatrevorjay/pr/zsh-plugin 1901dbe Merge pull request #19 from DrVanScott/master 6bcbc7b Add zsh-style plugin for easy load 37bccee fix _typeset_functions_about for functions starting with a dash 27623a9 fix zsh specific issues 2efc446 glossary: list only functions containing 'about' 7899d11 glossary: call _typeset_functions only once 072856e shell(): Fix for cygwin environment 2dc31de avoid error message if gprintf does not exist git-subtree-dir: vendor/github.com/erichs/composure git-subtree-split: 55fdb9fa3cd0f181208a46d90da4d87d5b7e4351 --- LICENSE | 16 ++++++++++++++++ README.md | 2 ++ composure.plugin.zsh | 2 ++ composure.sh | 40 ++++++++++++++++++++++++++-------------- 4 files changed, 46 insertions(+), 14 deletions(-) create mode 100644 LICENSE create mode 100644 composure.plugin.zsh diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000..d779d2d5e9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,16 @@ +License: The MIT License +Copyright © 2012, 2016 Erich Smith +Permission is hereby granted, free of charge, to any person obtaining a copy of this +software and associated documentation files (the "Software"), to deal in the Software +without restriction, including without limitation the rights to use, copy, modify, +merge, publish, distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to the following +conditions: +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE +OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index 67a05b1f96..e1f9bb8c3c 100644 --- a/README.md +++ b/README.md @@ -238,3 +238,5 @@ text](http://mitpress.mit.edu/sicp/full-text/book/book.html): ## Known Issues 'glossary ()' and 'reference ()' do not support nested functions with metadata. + +`revise` works well if your editor is terminal-based, like Emacs or Vim. If you use a windowed editor like Atom, VSCode, or Sublime, you will need to check to see if your editor supports a flag argument that allows it to wait for the files to be closed before returning. If this is supported, you can create a small script to launch your editor in this mode, and specify that script path in your `EDITOR` var. See https://github.com/erichs/composure/issues/10. diff --git a/composure.plugin.zsh b/composure.plugin.zsh new file mode 100644 index 0000000000..6710252966 --- /dev/null +++ b/composure.plugin.zsh @@ -0,0 +1,2 @@ +#!/bin/zsh +source ${0:h}/{composure,c_extras}.sh diff --git a/composure.sh b/composure.sh index d967a4722f..0c21fe0838 100755 --- a/composure.sh +++ b/composure.sh @@ -58,14 +58,14 @@ _determine_printf_cmd() { if [ -z "$_printf_cmd" ]; then _printf_cmd=printf # prefer GNU gprintf if available - [ -x "$(which gprintf)" ] && _printf_cmd=gprintf + [ -x "$(which gprintf 2>/dev/null)" ] && _printf_cmd=gprintf export _printf_cmd fi } _longest_function_name_length () { - _typeset_functions | awk 'BEGIN{ maxlength=0 } + echo "$1" | awk 'BEGIN{ maxlength=0 } { for(i=1;i<=NF;i++) if (length($i)>maxlength) @@ -174,23 +174,34 @@ _transcribe () } _typeset_functions () +{ + # unfortunately, there does not seem to be a easy, portable way to list just the + # names of the defined shell functions... + + case "$(_shell)" in + sh|bash) + typeset -F | awk '{print $3}' + ;; + *) + # trim everything following '()' in ksh/zsh + typeset +f | sed 's/().*$//' + ;; + esac +} + +_typeset_functions_about () { typeset f - for f in "$(_get_composure_dir)"/*.inc; do - # Without nullglob, we'll get back the glob - [[ -f "$f" ]] || continue - - f="${f##*/}" - f="${f%.inc}" - echo "$f" - done | cat - <(echo "cite\ndraft\nglossary\nmetafor\nreference\nrevise\nwrite") | sort | uniq + for f in $(_typeset_functions); do + typeset -f -- "$f" | grep -qE "^about[[:space:]]|[[:space:]]about[[:space:]]" && echo -- "$f" + done } _shell () { # here's a hack I modified from a StackOverflow post: # get the ps listing for the current process ($$), and print the last column (CMD) # stripping any leading hyphens shells sometimes throw in there - typeset this=$(ps -p $$ | tail -1 | awk '{print $4}' | sed 's/^-*//') + typeset this=$(ps -o comm -p $$ | tail -1 | awk '{print $NF}' | sed 's/^-*//') echo "${this##*/}" # e.g. /bin/bash => bash } @@ -329,9 +340,10 @@ glossary () group 'composure' typeset targetgroup=${1:-} - typeset maxwidth=$(_longest_function_name_length | awk '{print $1 + 5}') + typeset functionlist="$(_typeset_functions_about)" + typeset maxwidth=$(_longest_function_name_length "$functionlist" | awk '{print $1 + 5}') - for func in $(_typeset_functions); do + for func in $(echo $functionlist); do if [ "X${targetgroup}X" != "XX" ]; then typeset group="$(typeset -f -- $func | metafor group)" @@ -528,7 +540,7 @@ _bootstrap_composure : <