(um-next) : change the um/next.sh interface to call this function
um/next.sh now has minimal elisp, and calls this function instead, and only prints the next file with UMNEXTPRINT so that (um-next-shell) can just get the next file and feed it into (next-file) and we don't have to call (undo) to leave out the header
This commit is contained in:
parent
cd69c9af55
commit
e28aca4de0
3 changed files with 42 additions and 21 deletions
33
elisp/um.el
33
elisp/um.el
|
|
@ -205,20 +205,37 @@ NOTE: this searches in the current project root only.
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; shell integration
|
;; shell integration
|
||||||
|
|
||||||
(defun um-next-file-shell (dir &optional descriptor header)
|
(defun um-next (next-file &optional tag skip-header)
|
||||||
|
"Takes the next-file generated by the shell script and opens it.
|
||||||
|
|
||||||
|
With the optional tag generated by the script.
|
||||||
|
And the option not to insert the um-journal-header.
|
||||||
|
"
|
||||||
|
(find-file next-file)
|
||||||
|
(unless skip-header
|
||||||
|
(um-journal-header)
|
||||||
|
(if tag
|
||||||
|
(progn (previous-line)
|
||||||
|
(insert (format "+ %s\n" tag))
|
||||||
|
(next-line))))
|
||||||
|
(message (format "creating %s" next-file))
|
||||||
|
)
|
||||||
|
|
||||||
|
(defun um-next-shell (dir &optional descriptor header)
|
||||||
"Calls um next in the provided dir.
|
"Calls um next in the provided dir.
|
||||||
|
|
||||||
With the option not to leave behind the um-journal-header.
|
With the option not to leave behind the um-journal-header.
|
||||||
|
|
||||||
|
Returns the value of next-file computed by um next
|
||||||
"
|
"
|
||||||
(let ((default-directory dir))
|
(let ((default-directory dir) (next-file))
|
||||||
;; https://emacs.stackexchange.com/a/19878
|
;; https://emacs.stackexchange.com/a/19878
|
||||||
(eval (car (read-from-string (shell-command-to-string (concat "export UMNEXTECHO=true; um next" descriptor)))))
|
(setq next-file (shell-command-to-string
|
||||||
;; HACK: so that the um-journal-header doesn't
|
(concat "export UMNEXTPRINT=true; um next"
|
||||||
;; leave the file modified.
|
(concat " " descriptor))))
|
||||||
(unless header
|
(um-next next-file nil t)
|
||||||
(undo))
|
next-file
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
(provide 'um)
|
(provide 'um)
|
||||||
|
|
|
||||||
|
|
@ -30,24 +30,28 @@ LASTFILE=`$UMBASEPATH/last.sh || echo $UMDEFAULTINIT`
|
||||||
NEXTFILE=`echo $LASTFILE | awk -f $UMBASEPATH/next.awk -v arg=$1`
|
NEXTFILE=`echo $LASTFILE | awk -f $UMBASEPATH/next.awk -v arg=$1`
|
||||||
|
|
||||||
# tag is optional second arg to this script
|
# tag is optional second arg to this script
|
||||||
TAGINSERT='(previous-line) (insert "+ %s\\n") (next-line)'
|
|
||||||
if [ $2 ]; then
|
if [ $2 ]; then
|
||||||
# + means insert the string descriptor as tag
|
# + means insert the string descriptor as tag
|
||||||
if [ $2 = '+' ]; then
|
if [ $2 = '+' ]; then
|
||||||
UMTAG=$(printf "$TAGINSERT" "$1")
|
UMTAG="$1"
|
||||||
else
|
else
|
||||||
UMTAG=$(printf "$TAGINSERT" "$2")
|
UMTAG="$2"
|
||||||
fi
|
fi
|
||||||
|
UMELISP=$(printf '(um-next "%s" "%s")' "$NEXTFILE" "$UMTAG")
|
||||||
|
else
|
||||||
|
UMELISP=$(printf '(um-next "%s")' "$NEXTFILE")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
UMELISP="(progn (setq um-next-file \"$NEXTFILE\") (find-file um-next-file) (um-journal-header) $UMTAG (message \"creating $NEXTFILE\"))"
|
|
||||||
|
|
||||||
# for testing and piping
|
# for testing and piping
|
||||||
if [ $UMNEXTECHO ]; then
|
if [ $UMNEXTPRINT ]; then
|
||||||
|
# NOTE: printf instead of echo, because echo inserts a newline, and we pipe
|
||||||
|
# this back into elisp for um-next-shell:
|
||||||
|
printf $NEXTFILE
|
||||||
|
elif [ $UMNEXTTEST ]; then
|
||||||
echo $UMELISP
|
echo $UMELISP
|
||||||
else
|
else
|
||||||
# HACK: emacs won't accept piped input as a file name, so we use --eval to open
|
# NOTE: emacs won't accept piped input as a file name, so we use --eval to run
|
||||||
# the file via find-file.
|
# um-next as elisp. Which also lets us add the header and tag.
|
||||||
emacsclient --eval "$UMELISP"
|
emacsclient --eval "$UMELISP"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,11 +13,11 @@ setup() {
|
||||||
export ORIGPWD=`pwd`
|
export ORIGPWD=`pwd`
|
||||||
cd $DIR/mockjournal
|
cd $DIR/mockjournal
|
||||||
# so that we can run next.sh without dealing with emacsclient.
|
# so that we can run next.sh without dealing with emacsclient.
|
||||||
export UMNEXTECHO=true
|
export UMNEXTTEST=true
|
||||||
}
|
}
|
||||||
|
|
||||||
teardown() {
|
teardown() {
|
||||||
export UMNEXTECHO=false
|
export UMNEXTTEST=false
|
||||||
cd $ORIGPWD
|
cd $ORIGPWD
|
||||||
git restore $DIR/mockjournal
|
git restore $DIR/mockjournal
|
||||||
}
|
}
|
||||||
|
|
@ -46,7 +46,7 @@ um_next_awk() {
|
||||||
|
|
||||||
@test "um next empty elisp" {
|
@test "um next empty elisp" {
|
||||||
run um next
|
run um next
|
||||||
assert_output '(progn (setq um-next-file "100.md") (find-file um-next-file) (um-journal-header) (message "creating 100.md"))'
|
assert_output '(um-next "100.md")'
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "um next descriptor" {
|
@test "um next descriptor" {
|
||||||
|
|
@ -56,12 +56,12 @@ um_next_awk() {
|
||||||
|
|
||||||
@test "um next descriptor tag" {
|
@test "um next descriptor tag" {
|
||||||
run um next foo bar
|
run um next foo bar
|
||||||
assert_output --partial '(insert "+ bar\n")'
|
assert_output '(um-next "100.foo.md" "bar")'
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "um next descriptor +" {
|
@test "um next descriptor +" {
|
||||||
run um next foo +
|
run um next foo +
|
||||||
assert_output --partial '(insert "+ foo\n")'
|
assert_output '(um-next "100.foo.md" "foo")'
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "um last" {
|
@test "um last" {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue