From 331f1950544f70ef49d3c147f83a01b179d1c319 Mon Sep 17 00:00:00 2001 From: leizhe Date: Sun, 17 Oct 2021 15:30:14 +0800 Subject: [PATCH] cleanup: arguments in some commands --- src/main/frontend/handler/editor.cljs | 12 ++++++------ src/main/frontend/util/clock.cljs | 10 +++++----- src/main/frontend/util/drawer.cljs | 17 ++++++++++------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index 7fa028ba0..ef4be40cb 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -296,7 +296,7 @@ (nil? (db/entity x)))) refs)) (defn- with-marker-time - [content block format new-marker old-marker] + [content block new-marker old-marker] (if (and (state/enable-timetracking?) new-marker) (try (let [logbook-exists? (and (:block/body block) (drawer/get-logbook (:block/body block))) @@ -309,14 +309,14 @@ (and (= old-marker "later") (= new-marker "now")) (and (= old-marker new-marker "now") (not logbook-exists?)) (and (= old-marker new-marker "doing") (not logbook-exists?))) - (clock/clock-in format content) + (clock/clock-in content) (or (and (= old-marker "doing") (= new-marker "todo")) (and (= old-marker "now") (= new-marker "later")) (and (contains? #{"now" "doing"} old-marker) (= new-marker "done"))) - (clock/clock-out format content) + (clock/clock-out content) :else content)] @@ -330,7 +330,7 @@ (if (and (state/enable-timetracking?) (not= (:block/content block) value)) (let [new-marker (first (util/safe-re-find marker/bare-marker-pattern (or value ""))) - new-value (with-marker-time value block (:block/format block) + new-value (with-marker-time value block new-marker (:block/marker block))] new-value) @@ -796,9 +796,9 @@ (string/replace content old new)) content)) content (string/replace-first content "DOING" "TODO") - content (clock/clock-out format content) + content (clock/clock-out content) content (drawer/insert-drawer - format content "logbook" + content "logbook" (util/format (str (if (= :org format) "-" "*") " State \"DONE\" from \"%s\" [%s]") marker diff --git a/src/main/frontend/util/clock.cljs b/src/main/frontend/util/clock.cljs index d97d4e514..255c51351 100644 --- a/src/main/frontend/util/clock.cljs +++ b/src/main/frontend/util/clock.cljs @@ -23,17 +23,17 @@ (if (zero? minutes) "" (str minutes "m"))))) (defn clock-in - [format content] + [content] (drawer/insert-drawer - format content "logbook" + content "logbook" (util/format "CLOCK: [%s]" (date/get-date-time-string-3)))) (defn clock-out - [format content] + [content] (try (or - (when-let [clock-in-log (last (last (drawer/get-drawer-ast format content "logbook")))] + (when-let [clock-in-log (last (last (drawer/get-drawer-ast content "logbook")))] (let [clock-in-log (string/trim clock-in-log)] (when (string/starts-with? clock-in-log "CLOCK:") (let [clock-start (subs clock-in-log 8 (- (count clock-in-log) 1)) @@ -50,7 +50,7 @@ (str clock-in-log "\n") (str clock-out-log "\n")))))) content) - (catch js/Error e + (catch js/Error _error content))) (defn clock-summary diff --git a/src/main/frontend/util/drawer.cljs b/src/main/frontend/util/drawer.cljs index 599db11b8..0eb96d04c 100644 --- a/src/main/frontend/util/drawer.cljs +++ b/src/main/frontend/util/drawer.cljs @@ -2,7 +2,8 @@ (:require [clojure.string :as string] [frontend.util :as util] [frontend.util.property :as property] - [frontend.format.mldoc :as mldoc])) + [frontend.format.mldoc :as mldoc] + [frontend.state :as state])) (defn drawer-start [typ] @@ -21,17 +22,19 @@ (string/join "\n" [(drawer-start typ) drawer-end])))) (defn get-drawer-ast - [format content typ] - (let [ast (mldoc/->edn content (mldoc/default-config format)) + [content typ] + (let [format (state/get-preferred-format) + ast (mldoc/->edn content (mldoc/default-config format)) typ-drawer (ffirst (filter (fn [x] (mldoc/typ-drawer? x typ)) ast))] typ-drawer)) (defn insert-drawer - [format content typ value] + [content typ value] (when (string? content) (try - (let [ast (mldoc/->edn content (mldoc/default-config format)) + (let [format (state/get-preferred-format) + ast (mldoc/->edn content (mldoc/default-config format)) has-properties? (some (fn [x] (mldoc/properties? x)) ast) has-typ-drawer? (some (fn [x] (mldoc/typ-drawer? x typ)) ast) lines (string/split-lines content) @@ -123,7 +126,7 @@ (defn with-logbook [block content] - (let [new-clocks (last (get-drawer-ast (:block/format block) content "logbook")) + (let [new-clocks (last (get-drawer-ast content "logbook")) logbook (get-logbook (:block/body block))] (if logbook (let [content (remove-logbook content) @@ -133,6 +136,6 @@ (remove string/blank?) (string/join "\n"))] (if (:block/title block) - (insert-drawer (:block/format block) content "LOGBOOK" clocks) + (insert-drawer content "LOGBOOK" clocks) content)) content)))