From 124954420a1b44759edd17fb00de4e274b513200 Mon Sep 17 00:00:00 2001 From: bth Date: Fri, 30 Aug 2024 17:21:38 -0700 Subject: [PATCH] um-next takes a list of tags, as a comma separated string remove the '+' logic from the shell component. i'm getting closer to just moving all logic into elisp. but that awk is so great. --- README.md | 16 ++++++++++++++++ elisp/um.el | 23 ++++++++++++++--------- shell/next.sh | 8 +------- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index a2fa7bf..7354ec2 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,22 @@ Yields: + foo ``` +Or send a list of tags separated by commas. `+` still works: + +```sh +um next foo +,bar,baz +``` + +Yields: + +```markdown +# 05.foo.md +: 2024.01.14 ++ foo ++ bar ++ baz +``` + ## last `um last` will print the name of the last numbered file. This can be useful on its own, or like this: diff --git a/elisp/um.el b/elisp/um.el index 5481b76..34ddb11 100644 --- a/elisp/um.el +++ b/elisp/um.el @@ -201,19 +201,24 @@ NOTE: this searches in the current project root only. ;; shell integration ;;;###autoload -(defun um-next (next-file &optional tag skip-header) +(defun um-next (next-file &optional tags 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. +Optional TAGS string may contain more than one tag separated by a comma. +The SKIP-HEADER option says not to insert the um-journal-header at all, +in which case TAGS is also ignored. " - (find-file next-file) + (find-file next-file) (unless skip-header - (um-journal-header) - (if tag - (progn (forward-line -1) - (insert (format "+ %s\n" tag)) - (forward-line)))) + (um-journal-header) + (if tags + (progn (forward-line -1) + (dolist (tag (split-string tags ",")) + (insert (format "+ %s\n" + (if (equal "+" tag) + (cadr (split-string next-file "\\.")) + tag)))) + (forward-line)))) (message (format "creating %s" next-file)) ) diff --git a/shell/next.sh b/shell/next.sh index 18dd05d..e54db7c 100755 --- a/shell/next.sh +++ b/shell/next.sh @@ -31,13 +31,7 @@ NEXTFILE=`echo $LASTFILE | awk -f $UMBASEPATH/next.awk -v arg=$1` # tag is optional second arg to this script if [ $2 ]; then - # + means insert the string descriptor as tag - if [ $2 = '+' ]; then - UMTAG="$1" - else - UMTAG="$2" - fi - UMELISP=$(printf '(um-next "%s" "%s")' "$NEXTFILE" "$UMTAG") + UMELISP=$(printf '(um-next "%s" "%s")' "$NEXTFILE" "$2") else UMELISP=$(printf '(um-next "%s")' "$NEXTFILE") fi