summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Ecay <aaronecay@gmail.com>2018-05-10 01:35:08 +0100
committerAaron Ecay <aaronecay@gmail.com>2018-05-10 04:22:30 +0100
commitc9dd7a6a9de34b8094ad6a419260fcc1214cc791 (patch)
tree6721fcc4d16c0524100464c08ea30d92acdea6c8
parent673165c0352cf65d8ba3c17c997344b46bcc6a75 (diff)
downloadorg-mode-c9dd7a6a9de34b8094ad6a419260fcc1214cc791.tar.gz
org-agenda: one-armed “if” -> “when”
* lisp/org-agenda.el (org-agenda-mode): (org-agenda-undo, org-agenda): (org-agenda-get-restriction-and-command): (org-batch-agenda-csv, org-fix-agenda-info): (org-agenda-get-some-entry-text): (org-agenda-prepare, org-agenda-finalize): (org-agenda-fontify-priorities, org-agenda-entry-text-hide): (org-agenda-list, org-agenda-ndays-to-span): (org-search-view, org-todo-list): (org-tags-view, org-modify-diary-entry-string): (org-agenda-get-day-entries, org-agenda-get-progress): (org-agenda-get-deadlines, org-prefix-category-max-length): (org-agenda-format-item, org-agenda-fix-displayed-tags): (org-compile-prefix-format): (org-agenda-before-sorting-filter-function): (org-agenda-limit-interactively, org-cmp-time): (org-agenda-set-restriction-lock-from-agenda): (org-agenda-get-represented-tags, org-agenda-filter-apply): (org-agenda-filter-top-headline-apply): (org-agenda-remove-filter, org-agenda-compute-starting-span): (org-unhighlight, org-unhighlight-once): (org-agenda-show-tags, org-agenda-check-no-diary): (org-agenda-date-later-minutes, org-agenda-diary-entry-in-org-file): (org-agenda-add-entry-to-org-agenda-diary-file): (org-agenda-bulk-unmark, org-agenda-to-appt): Convert ‘if’ without ‘else’ to ‘when,’ or ‘unless’ in the case of “(if (not ...))” (org-batch-agenda-csv): Also convert while-catch to dolist. (org-agenda-prepare): Also simplify a quasiquoted structure. (org-agenda-entry-text-hide): Also convert a bogus ‘mapcar’ to ‘mapc’. (org-compile-prefix-format): Also convert sequential ‘if’s to ‘cl-case’.
-rw-r--r--lisp/org-agenda.el650
1 files changed, 322 insertions, 328 deletions
diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index e1745f9..2f93d4b 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -2217,7 +2217,7 @@ The following commands are available:
(setq indent-tabs-mode nil)
(use-local-map org-agenda-mode-map)
(easy-menu-add org-agenda-menu)
- (if org-startup-truncated (setq truncate-lines t))
+ (when org-startup-truncated (setq truncate-lines t))
(setq-local line-move-visual nil)
(add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
(add-hook 'pre-command-hook 'org-unhighlight nil 'local)
@@ -2564,30 +2564,30 @@ that have been changed along."
(interactive)
(or org-agenda-allow-remote-undo
(user-error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
- (if (not (eq this-command last-command))
- (setq org-agenda-undo-has-started-in nil
- org-agenda-pending-undo-list org-agenda-undo-list))
- (if (not org-agenda-pending-undo-list)
- (user-error "No further undo information"))
+ (when (not (eq this-command last-command))
+ (setq org-agenda-undo-has-started-in nil
+ org-agenda-pending-undo-list org-agenda-undo-list))
+ (when (not org-agenda-pending-undo-list)
+ (user-error "No further undo information"))
(let* ((entry (pop org-agenda-pending-undo-list))
buf line cmd rembuf)
(setq cmd (pop entry) line (pop entry))
(setq rembuf (nth 2 entry))
(org-with-remote-undo rembuf
(while (bufferp (setq buf (pop entry)))
- (if (pop entry)
- (with-current-buffer buf
- (let ((last-undo-buffer buf)
- (inhibit-read-only t))
- (unless (memq buf org-agenda-undo-has-started-in)
- (push buf org-agenda-undo-has-started-in)
- (make-local-variable 'pending-undo-list)
- (undo-start))
- (while (and pending-undo-list
- (listp pending-undo-list)
- (not (car pending-undo-list)))
- (pop pending-undo-list))
- (undo-more 1))))))
+ (when (pop entry)
+ (with-current-buffer buf
+ (let ((last-undo-buffer buf)
+ (inhibit-read-only t))
+ (unless (memq buf org-agenda-undo-has-started-in)
+ (push buf org-agenda-undo-has-started-in)
+ (make-local-variable 'pending-undo-list)
+ (undo-start))
+ (while (and pending-undo-list
+ (listp pending-undo-list)
+ (not (car pending-undo-list)))
+ (pop pending-undo-list))
+ (undo-more 1))))))
(org-goto-line line)
(message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
@@ -2810,9 +2810,9 @@ Pressing `<' twice means to restrict to the current subtree or region
;; If we have sticky agenda buffers, set a name for the buffer,
;; depending on the invoking keys. The user may still set this
;; as a command option, which will overwrite what we do here.
- (if org-agenda-sticky
- (setq org-agenda-buffer-name
- (format "*Org Agenda(%s)*" org-keys)))
+ (when org-agenda-sticky
+ (setq org-agenda-buffer-name
+ (format "*Org Agenda(%s)*" org-keys)))
;; Establish the restriction, if any
(when (and (not org-agenda-overriding-restriction) restriction)
(put 'org-agenda-files 'org-restrict (list bfn))
@@ -2836,10 +2836,10 @@ Pressing `<' twice means to restrict to the current subtree or region
(progn
(setq type (nth 2 entry) org-match (eval (nth 3 entry))
lprops (nth 4 entry))
- (if org-agenda-sticky
- (setq org-agenda-buffer-name
- (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
- (format "*Org Agenda(%s)*" org-keys))))
+ (when org-agenda-sticky
+ (setq org-agenda-buffer-name
+ (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
+ (format "*Org Agenda(%s)*" org-keys))))
(put 'org-agenda-redo-command 'org-lprops lprops)
(cond
((eq type 'agenda)
@@ -3023,10 +3023,10 @@ s Search for keywords M Like m, but only TODO entries
(org-add-props match nil 'face 'org-warning))
((listp type)
(format "set of %d commands" (length type))))))
- (if (org-string-nw-p match)
- (add-text-properties
- 0 (length line) (list 'help-echo
- (concat "Matcher: " match)) line)))
+ (when (org-string-nw-p match)
+ (add-text-properties
+ 0 (length line) (list 'help-echo
+ (concat "Matcher: " match)) line)))
(push line lines)))
(setq lines (nreverse lines))
(when prefixes
@@ -3062,8 +3062,8 @@ s Search for keywords M Like m, but only TODO entries
;; Make the window the right size
(goto-char (point-min))
(if second-time
- (if (not (pos-visible-in-window-p (point-max)))
- (org-fit-window-to-buffer))
+ (when (not (pos-visible-in-window-p (point-max)))
+ (org-fit-window-to-buffer))
(setq second-time t)
(org-fit-window-to-buffer))
@@ -3259,11 +3259,9 @@ agenda-day The day in the agenda where this is listed"
(org-tags-view nil cmd-key)
(org-agenda nil cmd-key)))
(set-buffer org-agenda-buffer-name)
- (let* ((lines (org-split-string (buffer-string) "\n"))
- line)
- (while (setq line (pop lines))
- (catch 'next
- (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
+ (let ((lines (org-split-string (buffer-string) "\n")))
+ (dolist (line lines)
+ (when (get-text-property 0 'org-category line)
(setq org-agenda-info
(org-fix-agenda-info (text-properties-at 0 line)))
(princ
@@ -3280,14 +3278,14 @@ This ensures the export commands can easily use it."
(when (setq tmp (plist-get props 'tags))
(setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
(when (setq tmp (plist-get props 'date))
- (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
+ (when (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
(let ((calendar-date-display-form '(year "-" month "-" day)))
'((format "%4d, %9s %2s, %4s" dayname monthname day year))
(setq tmp (calendar-date-string tmp)))
(setq props (plist-put props 'date tmp)))
(when (setq tmp (plist-get props 'day))
- (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
+ (when (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
(let ((calendar-date-display-form '(year "-" month "-" day)))
(setq tmp (calendar-date-string tmp)))
(setq props (plist-put props 'day tmp))
@@ -3550,7 +3548,7 @@ removed from the entry content. Currently only `planning' is allowed here."
(replace-match "")))))
(goto-char (point-max))
(skip-chars-backward " \t\n")
- (if (looking-at "[ \t\n]+\\'") (replace-match ""))
+ (when (looking-at "[ \t\n]+\\'") (replace-match ""))
;; find and remove min common indentation
(goto-char (point-min))
@@ -3695,13 +3693,13 @@ FILTER-ALIST is an alist of filters we need to apply when
(or wconf org-agenda-pre-window-conf))))
(defun org-agenda-prepare (&optional name)
- (let ((filter-alist (if org-agenda-persistent-filter
- (with-current-buffer
- (get-buffer-create org-agenda-buffer-name)
- (list `(tag . ,org-agenda-tag-filter)
- `(re . ,org-agenda-regexp-filter)
- `(effort . ,org-agenda-effort-filter)
- `(cat . ,org-agenda-category-filter))))))
+ (let ((filter-alist (when org-agenda-persistent-filter
+ (with-current-buffer
+ (get-buffer-create org-agenda-buffer-name)
+ `((tag . ,org-agenda-tag-filter)
+ (re . ,org-agenda-regexp-filter)
+ (effort . ,org-agenda-effort-filter)
+ (cat . ,org-agenda-category-filter))))))
(if (org-agenda-use-sticky-p)
(progn
(put 'org-agenda-tag-filter :preset-filter nil)
@@ -3772,13 +3770,11 @@ FILTER-ALIST is an alist of filters we need to apply when
(org-agenda-align-tags))
(unless org-agenda-with-colors
(remove-text-properties (point-min) (point-max) '(face nil)))
- (if (and (boundp 'org-agenda-overriding-columns-format)
- org-agenda-overriding-columns-format)
- (setq-local org-agenda-overriding-columns-format
- org-agenda-overriding-columns-format))
- (if (and (boundp 'org-agenda-view-columns-initially)
- org-agenda-view-columns-initially)
- (org-agenda-columns))
+ (when (bound-and-true-p org-agenda-overriding-columns-format)
+ (setq-local org-agenda-overriding-columns-format
+ org-agenda-overriding-columns-format))
+ (when org-agenda-view-columns-initially
+ (org-agenda-columns))
(when org-agenda-fontify-priorities
(org-agenda-fontify-priorities))
(when (and org-agenda-dim-blocked-tasks org-blocker-hook)
@@ -3787,9 +3783,9 @@ FILTER-ALIST is an alist of filters we need to apply when
(when org-agenda-entry-text-mode
(org-agenda-entry-text-hide)
(org-agenda-entry-text-show))
- (if (and (functionp 'org-habit-insert-consistency-graphs)
- (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
- (org-habit-insert-consistency-graphs))
+ (when (and (featurep 'org-habit)
+ (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
+ (org-habit-insert-consistency-graphs))
(setq org-agenda-type (org-get-at-bol 'org-agenda-type))
(unless (or (eq org-agenda-show-inherited-tags 'always)
(and (listp org-agenda-show-inherited-tags)
@@ -3859,15 +3855,15 @@ FILTER-ALIST is an alist of filters we need to apply when
(defun org-agenda-unmark-clocking-task ()
"Unmark the current clocking task."
(mapc (lambda (o)
- (if (eq (overlay-get o 'type) 'org-agenda-clocking)
- (delete-overlay o)))
+ (when (eq (overlay-get o 'type) 'org-agenda-clocking)
+ (delete-overlay o)))
(overlays-in (point-min) (point-max))))
(defun org-agenda-fontify-priorities ()
"Make highest priority lines bold, and lowest italic."
(interactive)
- (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
- (delete-overlay o)))
+ (mapc (lambda (o) (when (eq (overlay-get o 'org-type) 'org-priority)
+ (delete-overlay o)))
(overlays-in (point-min) (point-max)))
(save-excursion
(let (b e p ov h l)
@@ -4067,12 +4063,11 @@ This check for agenda markers in all agenda buffers currently active."
(defun org-agenda-entry-text-hide ()
"Remove any shown entry context."
- (delq nil
- (mapcar (lambda (o)
- (if (eq (overlay-get o 'org-overlay-type)
- 'agenda-entry-content)
- (progn (delete-overlay o) t)))
- (overlays-in (point-min) (point-max)))))
+ (mapc (lambda (o)
+ (when (eq (overlay-get o 'org-overlay-type)
+ 'agenda-entry-content)
+ (delete-overlay o)))
+ (overlays-in (point-min) (point-max))))
(defun org-agenda-get-day-face (date)
"Return the face DATE should be displayed with."
@@ -4113,28 +4108,28 @@ given in `org-agenda-start-on-weekday'.
When WITH-HOUR is non-nil, only include scheduled and deadline
items if they have an hour specification like [h]h:mm."
(interactive "P")
- (if org-agenda-overriding-arguments
- (setq arg (car org-agenda-overriding-arguments)
- start-day (nth 1 org-agenda-overriding-arguments)
- span (nth 2 org-agenda-overriding-arguments)))
- (if (and (integerp arg) (> arg 0))
- (setq span arg arg nil))
+ (when org-agenda-overriding-arguments
+ (setq arg (car org-agenda-overriding-arguments)
+ start-day (nth 1 org-agenda-overriding-arguments)
+ span (nth 2 org-agenda-overriding-arguments)))
+ (when (and (integerp arg) (> arg 0))
+ (setq span arg arg nil))
(catch 'exit
(setq org-agenda-buffer-name
(or org-agenda-buffer-tmp-name
(and org-agenda-doing-sticky-redo org-agenda-buffer-name)
- (if org-agenda-sticky
- (cond ((and org-keys (stringp org-match))
- (format "*Org Agenda(%s:%s)*" org-keys org-match))
- (org-keys
- (format "*Org Agenda(%s)*" org-keys))
- (t "*Org Agenda(a)*")))
+ (when org-agenda-sticky
+ (cond ((and org-keys (stringp org-match))
+ (format "*Org Agenda(%s:%s)*" org-keys org-match))
+ (org-keys
+ (format "*Org Agenda(%s)*" org-keys))
+ (t "*Org Agenda(a)*")))
"*Org Agenda*"))
(org-agenda-prepare "Day/Week")
(setq start-day (or start-day org-agenda-start-day))
- (if (stringp start-day)
- ;; Convert to an absolute day number
- (setq start-day (time-to-days (org-read-date nil t start-day))))
+ (when (stringp start-day)
+ ;; Convert to an absolute day number
+ (setq start-day (time-to-days (org-read-date nil t start-day))))
(org-compile-prefix-format 'agenda)
(org-set-sorting-strategy 'agenda)
(let* ((span (org-agenda-ndays-to-span (or span org-agenda-span)))
@@ -4142,8 +4137,8 @@ items if they have an hour specification like [h]h:mm."
(sd (or start-day today))
(ndays (org-agenda-span-to-ndays span sd))
(org-agenda-start-on-weekday
- (if (or (eq ndays 7) (eq ndays 14))
- org-agenda-start-on-weekday))
+ (and (or (eq ndays 7) (eq ndays 14))
+ org-agenda-start-on-weekday))
(thefiles (org-agenda-files nil 'ifmode))
(files thefiles)
(start (if (or (null org-agenda-start-on-weekday)
@@ -4192,8 +4187,8 @@ items if they have an hour specification like [h]h:mm."
(if (or (setq todayp (= d today))
(and (not start-pos) (= d sd)))
(setq start-pos (point))
- (if (and start-pos (not end-pos))
- (setq end-pos (point))))
+ (when (and start-pos (not end-pos))
+ (setq end-pos (point))))
(setq files thefiles
rtnall nil)
(while (setq file (pop files))
@@ -4233,34 +4228,33 @@ items if they have an hour specification like [h]h:mm."
file date
org-agenda-entry-types)))))
(setq rtnall (append rtnall rtn)))) ;; all entries
- (if org-agenda-include-diary
- (let ((org-agenda-search-headline-for-time t))
- (require 'diary-lib)
- (setq rtn (org-get-entries-from-diary date))
- (setq rtnall (append rtnall rtn))))
- (if (or rtnall org-agenda-show-all-dates)
- (progn
- (setq day-cnt (1+ day-cnt))
- (insert
- (if (stringp org-agenda-format-date)
- (format-time-string org-agenda-format-date
- (org-time-from-absolute date))
- (funcall org-agenda-format-date date))
- "\n")
- (put-text-property s (1- (point)) 'face
- (org-agenda-get-day-face date))
- (put-text-property s (1- (point)) 'org-date-line t)
- (put-text-property s (1- (point)) 'org-agenda-date-header t)
- (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
- (when todayp
- (put-text-property s (1- (point)) 'org-today t))
- (setq rtnall
- (org-agenda-add-time-grid-maybe rtnall ndays todayp))
- (if rtnall (insert ;; all entries
- (org-agenda-finalize-entries rtnall 'agenda)
- "\n"))
- (put-text-property s (1- (point)) 'day d)
- (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
+ (when org-agenda-include-diary
+ (let ((org-agenda-search-headline-for-time t))
+ (require 'diary-lib)
+ (setq rtn (org-get-entries-from-diary date))
+ (setq rtnall (append rtnall rtn))))
+ (when (or rtnall org-agenda-show-all-dates)
+ (setq day-cnt (1+ day-cnt))
+ (insert
+ (if (stringp org-agenda-format-date)
+ (format-time-string org-agenda-format-date
+ (org-time-from-absolute date))
+ (funcall org-agenda-format-date date))
+ "\n")
+ (put-text-property s (1- (point)) 'face
+ (org-agenda-get-day-face date))
+ (put-text-property s (1- (point)) 'org-date-line t)
+ (put-text-property s (1- (point)) 'org-agenda-date-header t)
+ (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
+ (when todayp
+ (put-text-property s (1- (point)) 'org-today t))
+ (setq rtnall
+ (org-agenda-add-time-grid-maybe rtnall ndays todayp))
+ (when rtnall (insert ;; all entries
+ (org-agenda-finalize-entries rtnall 'agenda)
+ "\n"))
+ (put-text-property s (1- (point)) 'day d)
+ (put-text-property s (1- (point)) 'org-day-cnt day-cnt)))
(when (and org-agenda-clockreport-mode clocktable-start)
(let ((org-agenda-files (org-agenda-files nil 'ifmode))
;; the above line is to ensure the restricted range!
@@ -4279,18 +4273,17 @@ items if they have an hour specification like [h]h:mm."
(pos-visible-in-window-p (point-max))))
(goto-char (1- (point-max)))
(recenter -1)
- (if (not (pos-visible-in-window-p (or start-pos 1)))
- (progn
- (goto-char (or start-pos 1))
- (recenter 1))))
+ (when (not (pos-visible-in-window-p (or start-pos 1)))
+ (goto-char (or start-pos 1))
+ (recenter 1)))
(goto-char (or start-pos 1))
(add-text-properties (point-min) (point-max)
`(org-agenda-type agenda
org-last-args (,arg ,start-day ,span)
org-redo-cmd ,org-agenda-redo-command
org-series-cmd ,org-cmd))
- (if (eq org-agenda-show-log-scoped 'clockcheck)
- (org-agenda-show-clocking-issues))
+ (when (eq org-agenda-show-log-scoped 'clockcheck)
+ (org-agenda-show-clocking-issues))
(org-agenda-finalize)
(setq buffer-read-only t)
(message ""))))
@@ -4390,10 +4383,10 @@ This command searches the agenda files, and in addition the files
listed in `org-agenda-text-search-extra-files' unless a restriction lock
is active."
(interactive "P")
- (if org-agenda-overriding-arguments
- (setq todo-only (car org-agenda-overriding-arguments)
- string (nth 1 org-agenda-overriding-arguments)
- edit-at (nth 2 org-agenda-overriding-arguments)))
+ (when org-agenda-overriding-arguments
+ (setq todo-only (car org-agenda-overriding-arguments)
+ string (nth 1 org-agenda-overriding-arguments)
+ edit-at (nth 2 org-agenda-overriding-arguments)))
(let* ((props (list 'face nil
'done-face 'org-agenda-done
'org-not-done-regexp org-not-done-regexp
@@ -4418,12 +4411,12 @@ is active."
(edit-at string))
'org-agenda-search-history)))
(catch 'exit
- (if org-agenda-sticky
- (setq org-agenda-buffer-name
- (if (stringp string)
- (format "*Org Agenda(%s:%s)*"
- (or org-keys (or (and todo-only "S") "s")) string)
- (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
+ (when org-agenda-sticky
+ (setq org-agenda-buffer-name
+ (if (stringp string)
+ (format "*Org Agenda(%s:%s)*"
+ (or org-keys (or (and todo-only "S") "s")) string)
+ (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
(org-agenda-prepare "SEARCH")
(org-compile-prefix-format 'search)
(org-set-sorting-strategy 'search)
@@ -4441,9 +4434,9 @@ is active."
(when (equal (string-to-char words) ?:)
(setq full-words t
words (substring words 1)))
- (if (or org-agenda-search-view-always-boolean
- (member (string-to-char words) '(?- ?+ ?\{)))
- (setq boolean t))
+ (when (or org-agenda-search-view-always-boolean
+ (member (string-to-char words) '(?- ?+ ?\{)))
+ (setq boolean t))
(setq words (split-string words))
(let (www w)
(while (setq w (pop words))
@@ -4463,12 +4456,12 @@ is active."
(when boolean
(let (wds w)
(while (setq w (pop words))
- (if (or (equal (substring w 0 1) "\"")
- (and (> (length w) 1)
- (member (substring w 0 1) '("+" "-"))
- (equal (substring w 1 2) "\"")))
- (while (and words (not (equal (substring w -1) "\"")))
- (setq w (concat w " " (pop words)))))
+ (when (or (equal (substring w 0 1) "\"")
+ (and (> (length w) 1)
+ (member (substring w 0 1) '("+" "-"))
+ (equal (substring w 1 2) "\"")))
+ (while (and words (not (equal (substring w -1) "\"")))
+ (setq w (concat w " " (pop words)))))
(and (string-match "\\`\\([-+]?\\)\"" w)
(setq w (replace-match "\\1" nil nil w)))
(and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
@@ -4495,8 +4488,8 @@ is active."
(if (not regexps+)
(setq regexp org-outline-regexp-bol)
(setq regexp (pop regexps+))
- (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
- regexp))))
+ (when hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
+ regexp))))
(setq files (org-agenda-files nil 'ifmode))
;; Add `org-agenda-text-search-extra-files' unless there is some
;; restriction.
@@ -4520,10 +4513,10 @@ is active."
(setq buffer (if (file-exists-p file)
(org-get-agenda-file-buffer file)
(error "No such file %s" file)))
- (if (not buffer)
- ;; If file does not exist, make sure an error message is sent
- (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
- file))))
+ (unless buffer
+ ;; If file does not exist, make sure an error message is sent
+ (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
+ file))))
(with-current-buffer buffer
(with-syntax-table (org-search-syntax-table)
(unless (derived-mode-p 'org-mode)
@@ -4662,9 +4655,9 @@ the list to these. When using `\\[universal-argument]', you will be prompted
for a keyword. A numeric prefix directly selects the Nth keyword in
`org-todo-keywords-1'."
(interactive "P")
- (if org-agenda-overriding-arguments
- (setq arg org-agenda-overriding-arguments))
- (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
+ (when org-agenda-overriding-arguments
+ (setq arg org-agenda-overriding-arguments))
+ (when (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
(let* ((today (org-today))
(date (calendar-gregorian-from-absolute today))
(kwds org-todo-keywords-for-agenda)
@@ -4680,12 +4673,12 @@ for a keyword. A numeric prefix directly selects the Nth keyword in
(mapcar #'list kwds) nil nil)))
(and (equal 0 arg) (setq org-select-this-todo-keyword nil))
(catch 'exit
- (if org-agenda-sticky
- (setq org-agenda-buffer-name
- (if (stringp org-select-this-todo-keyword)
- (format "*Org Agenda(%s:%s)*" (or org-keys "t")
- org-select-this-todo-keyword)
- (format "*Org Agenda(%s)*" (or org-keys "t")))))
+ (when org-agenda-sticky
+ (setq org-agenda-buffer-name
+ (if (stringp org-select-this-todo-keyword)
+ (format "*Org Agenda(%s:%s)*" (or org-keys "t")
+ org-select-this-todo-keyword)
+ (format "*Org Agenda(%s)*" (or org-keys "t")))))
(org-agenda-prepare "TODO")
(org-compile-prefix-format 'todo)
(org-set-sorting-strategy 'todo)
@@ -4745,9 +4738,9 @@ for a keyword. A numeric prefix directly selects the Nth keyword in
"Show all headlines for all `org-agenda-files' matching a TAGS criterion.
The prefix arg TODO-ONLY limits the search to TODO entries."
(interactive "P")
- (if org-agenda-overriding-arguments
- (setq todo-only (car org-agenda-overriding-arguments)
- match (nth 1 org-agenda-overriding-arguments)))
+ (when org-agenda-overriding-arguments
+ (setq todo-only (car org-agenda-overriding-arguments)
+ match (nth 1 org-agenda-overriding-arguments)))
(let* ((org-tags-match-list-sublevels
org-tags-match-list-sublevels)
(completion-ignore-case t)
@@ -4757,13 +4750,13 @@ The prefix arg TODO-ONLY limits the search to TODO entries."
(when (and (stringp match) (not (string-match "\\S-" match)))
(setq match nil))
(catch 'exit
- (if org-agenda-sticky
- (setq org-agenda-buffer-name
- (if (stringp match)
- (format "*Org Agenda(%s:%s)*"
- (or org-keys (or (and todo-only "M") "m")) match)
- (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
- (setq matcher (org-make-tags-matcher match))
+ ;; TODO: this code is repeated a lot...
+ (when org-agenda-sticky
+ (setq org-agenda-buffer-name
+ (if (stringp match)
+ (format "*Org Agenda(%s:%s)*"
+ (or org-keys (or (and todo-only "M") "m")) match)
+ (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
;; Prepare agendas (and `org-tag-alist-for-agenda') before
;; expanding tags within `org-make-tags-matcher'
(org-agenda-prepare (concat "TAGS " match))
@@ -5104,8 +5097,8 @@ each date. It also removes lines that contain only whitespace."
(while (re-search-forward "^ +\n" nil t)
(replace-match ""))
(goto-char (point-min))
- (if (re-search-forward "^Org mode dummy\n?" nil t)
- (replace-match ""))
+ (when (re-search-forward "^Org mode dummy\n?" nil t)
+ (replace-match ""))
(run-hooks 'org-agenda-cleanup-fancy-diary-hook))
;; Make sure entries from the diary have the right text properties.
@@ -5198,7 +5191,7 @@ function from a program - use `org-agenda-get-day-entries' instead."
(setq org-diary-last-run-time time)
;; If this is called during org-agenda, don't return any entries to
;; the calendar. Org Agenda will list these entries itself.
- (if org-disable-agenda-to-diary (setq files nil))
+ (when org-disable-agenda-to-diary (setq files nil))
(while (setq file (pop files))
(setq rtn (apply 'org-agenda-get-day-entries file date args))
(setq results (append results rtn)))
@@ -5742,10 +5735,10 @@ then those holidays will be skipped."
(parts
(delq nil
(list
- (if (memq 'closed items) (concat "\\<" org-closed-string))
- (if (memq 'clock items) (concat "\\<" org-clock-string))
- (if (memq 'state items)
- (format "- State \"%s\".*?" org-todo-regexp)))))
+ (when (memq 'closed items) (concat "\\<" org-closed-string))
+ (when (memq 'clock items) (concat "\\<" org-clock-string))
+ (when (memq 'state items)
+ (format "- State \"%s\".*?" org-todo-regexp)))))
(parts-re (if parts (mapconcat 'identity parts "\\|")
(error "`org-agenda-log-mode-items' is empty")))
(regexp (concat
@@ -5920,11 +5913,11 @@ See also the user option `org-agenda-clock-consistency-checks'."
(unless ok-list
;; there are no OK times for gaps...
(throw 'exit nil))
- (if (> (- (/ t2 36000) (/ t1 36000)) 24)
- ;; This is more than 24 hours, so it is OK.
- ;; because we have at least one OK time, that must be in the
- ;; 24 hour interval.
- (throw 'exit t))
+ (when (> (- (/ t2 36000) (/ t1 36000)) 24)
+ ;; This is more than 24 hours, so it is OK.
+ ;; because we have at least one OK time, that must be in the
+ ;; 24 hour interval.
+ (throw 'exit t))
;; We have a shorter gap.
;; Now we have to get the minute of the day when these times are
(let* ((t1dec (decode-time (seconds-to-time t1)))
@@ -5939,7 +5932,7 @@ See also the user option `org-agenda-clock-consistency-checks'."
;; Now check if any of the OK times is in the gap
(mapc (lambda (x)
;; Wrap the time to after midnight if necessary
- (if (< x min1) (setq x (+ x 1440)))
+ (when (< x min1) (setq x (+ x 1440)))
;; Check if in interval
(and (<= min1 x) (>= min2 x) (throw 'exit t)))
ok-list)
@@ -6337,59 +6330,59 @@ scheduled items with an hour specification like [h]h:mm."
pos
(current-buffer)
(error-message-string err))))))
- (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
- ;; Only allow days between the limits, because the normal
- ;; date stamps will catch the limits.
- (save-excursion
- (setq todo-state (org-get-todo-state))
- (setq donep (member todo-state org-done-keywords))
- (if (and donep org-agenda-skip-timestamp-if-done)
- (throw :skip t))
- (setq marker (org-agenda-new-marker (point))
- category (org-get-category))
- (if (not (re-search-backward org-outline-regexp-bol nil t))
- (throw :skip nil)
- (goto-char (match-beginning 0))
- (setq hdmarker (org-agenda-new-marker (point))
- inherited-tags
- (or (eq org-agenda-show-inherited-tags 'always)
- (and (listp org-agenda-show-inherited-tags)
- (memq 'agenda org-agenda-show-inherited-tags))
- (and (eq org-agenda-show-inherited-tags t)
- (or (eq org-agenda-use-tag-inheritance t)
- (memq 'agenda org-agenda-use-tag-inheritance))))
-
- tags (org-get-tags nil (not inherited-tags)))
- (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
- (looking-at "\\*+[ \t]+\\(.*\\)")
- (setq head (match-string 1))
- (let ((remove-re
- (if org-agenda-remove-timeranges-from-blocks
- (concat
- "<" (regexp-quote s1) ".*?>"
- "--"
- "<" (regexp-quote s2) ".*?>")
- nil)))
- (setq txt (org-agenda-format-item
- (format
- (nth (if (= d1 d2) 0 1)
- org-agenda-timerange-leaders)
- (1+ (- d0 d1)) (1+ (- d2 d1)))
- head level category tags
- (cond ((and (= d1 d0) (= d2 d0))
- (concat "<" start-time ">--<" end-time ">"))
- ((= d1 d0)
- (concat "<" start-time ">"))
- ((= d2 d0)
- (concat "<" end-time ">")))
- remove-re))))
- (org-add-props txt props
- 'org-marker marker 'org-hd-marker hdmarker
- 'type "block" 'date date
- 'level level
- 'todo-state todo-state
- 'priority (org-get-priority txt))
- (push txt ee))))
+ (when (and (> (- d0 d1) -1) (> (- d2 d0) -1))
+ ;; Only allow days between the limits, because the normal
+ ;; date stamps will catch the limits.
+ (save-excursion
+ (setq todo-state (org-get-todo-state))
+ (setq donep (member todo-state org-done-keywords))
+ (when (and donep org-agenda-skip-timestamp-if-done)
+ (throw :skip t))
+ (setq marker (org-agenda-new-marker (point))
+ category (org-get-category))
+ (if (not (re-search-backward org-outline-regexp-bol nil t))
+ (throw :skip nil)
+ (goto-char (match-beginning 0))
+ (setq hdmarker (org-agenda-new-marker (point))
+ inherited-tags
+ (or (eq org-agenda-show-inherited-tags 'always)
+ (and (listp org-agenda-show-inherited-tags)
+ (memq 'agenda org-agenda-show-inherited-tags))
+ (and (eq org-agenda-show-inherited-tags t)
+ (or (eq org-agenda-use-tag-inheritance t)
+ (memq 'agenda org-agenda-use-tag-inheritance))))
+
+ tags (org-get-tags nil (not inherited-tags)))
+ (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
+ (looking-at "\\*+[ \t]+\\(.*\\)")
+ (setq head (match-string 1))
+ (let ((remove-re
+ (if org-agenda-remove-timeranges-from-blocks
+ (concat
+ "<" (regexp-quote s1) ".*?>"
+ "--"
+ "<" (regexp-quote s2) ".*?>")
+ nil)))
+ (setq txt (org-agenda-format-item
+ (format
+ (nth (if (= d1 d2) 0 1)
+ org-agenda-timerange-leaders)
+ (1+ (- d0 d1)) (1+ (- d2 d1)))
+ head level category tags
+ (cond ((and (= d1 d0) (= d2 d0))
+ (concat "<" start-time ">--<" end-time ">"))
+ ((= d1 d0)
+ (concat "<" start-time ">"))
+ ((= d2 d0)
+ (concat "<" end-time ">")))
+ remove-re))))
+ (org-add-props txt props
+ 'org-marker marker 'org-hd-marker hdmarker
+ 'type "block" 'date date
+ 'level level
+ 'todo-state todo-state
+ 'priority (org-get-priority txt))
+ (push txt ee))))
(goto-char pos)))
;; Sort the entries by expiration date.
(nreverse ee)))
@@ -6473,9 +6466,9 @@ Any match of REMOVE-RE will be removed from TXT."
(tag (if tags (nth (1- (length tags)) tags) ""))
(time-grid-trailing-characters (nth 2 org-agenda-time-grid))
time
- (ts (if dotime (concat
- (if (stringp dotime) dotime "")
- (and org-agenda-search-headline-for-time txt))))
+ (ts (when dotime (concat
+ (if (stringp dotime) dotime "")
+ (and org-agenda-search-headline-for-time txt))))
(time-of-day (and dotime (org-get-time-of-day ts)))
stamp plain s0 s1 s2 rtn srp l
duration breadcrumbs)
@@ -6493,17 +6486,17 @@ Any match of REMOVE-RE will be removed from TXT."
;; If the times are in TXT (not in DOTIMES), and the prefix will list
;; them, we might want to remove them there to avoid duplication.
;; The user can turn this off with a variable.
- (if (and org-prefix-has-time
- org-agenda-remove-times-when-in-prefix (or stamp plain)
- (string-match (concat (regexp-quote s0) " *") txt)
- (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
- (if (eq org-agenda-remove-times-when-in-prefix 'beg)
- (= (match-beginning 0) 0)
- t))
- (setq txt (replace-match "" nil nil txt))))
+ (when (and org-prefix-has-time
+ org-agenda-remove-times-when-in-prefix (or stamp plain)
+ (string-match (concat (regexp-quote s0) " *") txt)
+ (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
+ (if (eq org-agenda-remove-times-when-in-prefix 'beg)
+ (= (match-beginning 0) 0)
+ t))
+ (setq txt (replace-match "" nil nil txt))))
;; Normalize the time(s) to 24 hour
- (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
- (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
+ (when s1 (setq s1 (org-get-time-of-day s1 'string t)))
+ (when s2 (setq s2 (org-get-time-of-day s2 'string t)))
;; Try to set s2 if s1 and
;; `org-agenda-default-appointment-duration' are set
@@ -6539,14 +6532,16 @@ Any match of REMOVE-RE will be removed from TXT."
(add-text-properties 0 (length txt) '(org-heading t) txt)
;; Prepare the variables needed in the eval of the compiled format
- (if org-prefix-has-breadcrumbs
- (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
- (let ((s (org-display-outline-path nil nil "->" t)))
- (if (eq "" s) "" (concat s "->"))))))
+ (when org-prefix-has-breadcrumbs
+ (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
+ (let ((s (org-format-outline-path (org-get-outline-path)
+ (1- (frame-width))
+ nil "->")))
+ (if (eq "" s) "" (concat s "->"))))))
(setq time (cond (s2 (concat
(org-agenda-time-of-day-to-ampm-maybe s1)
"-" (org-agenda-time-of-day-to-ampm-maybe s2)
- (if org-agenda-timegrid-use-ampm " ")))
+ (when org-agenda-timegrid-use-ampm " ")))
(s1 (concat
(org-agenda-time-of-day-to-ampm-maybe s1)
(if org-agenda-timegrid-use-ampm
@@ -6566,9 +6561,9 @@ Any match of REMOVE-RE will be removed from TXT."
(org-add-props category nil
'extra-space (make-string
(- org-prefix-category-length l 1) ?\ ))))
- (if (and org-prefix-category-max-length
- (>= (length category) org-prefix-category-max-length))
- (setq category (substring category 0 (1- org-prefix-category-max-length)))))
+ (when (and org-prefix-category-max-length
+ (>= (length category) org-prefix-category-max-length))
+ (setq category (substring category 0 (1- org-prefix-category-max-length)))))
;; Evaluate the compiled format
(setq rtn (concat (eval formatter) txt))
@@ -6594,8 +6589,8 @@ Any match of REMOVE-RE will be removed from TXT."
The modified list may contain inherited tags, and tags matched by
`org-agenda-hide-tags-regexp' will be removed."
(when (or add-inherited hide-re)
- (if (string-match org-tag-group-re txt)
- (setq txt (substring txt 0 (match-beginning 0))))
+ (when (string-match org-tag-group-re txt)
+ (setq txt (substring txt 0 (match-beginning 0))))
(setq tags
(delq nil
(mapcar (lambda (tg)
@@ -6649,9 +6644,9 @@ TODAYP is t when the current agenda view is on today."
(req (car org-agenda-time-grid))
(remove (member 'remove-match req))
new time)
- (if (and (member 'require-timed req) (not have))
- ;; don't show empty grid
- (throw 'exit list))
+ (when (and (member 'require-timed req) (not have))
+ ;; don't show empty grid
+ (throw 'exit list))
(while (setq time (pop gridtimes))
(unless (and remove (member time have))
(setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
@@ -6699,19 +6694,19 @@ and stored in the variable `org-prefix-format-compiled'."
c (or (match-string 3 s) "")
opt (match-beginning 1)
start (1+ (match-beginning 0)))
- (if (eq var 'time) (setq org-prefix-has-time t))
- (if (eq var 'tag) (setq org-prefix-has-tag t))
- (if (eq var 'effort) (setq org-prefix-has-effort t))
- (if (eq var 'breadcrumbs) (setq org-prefix-has-breadcrumbs t))
+ (cl-case var
+ (time (setq org-prefix-has-time t))
+ (tag (setq org-prefix-has-tag t))
+ (effort (setq org-prefix-has-effort t))
+ (breadcrumbs (setq org-prefix-has-breadcrumbs t)))
(setq f (concat "%" (match-string 2 s) "s"))
(when (eq var 'category)
(setq org-prefix-category-length
(floor (abs (string-to-number (match-string 2 s)))))
(setq org-prefix-category-max-length
(let ((x (match-string 2 s)))
- (save-match-data
- (if (string-match "\\.[0-9]+" x)
- (string-to-number (substring (match-string 0 x) 1)))))))
+ (when (string-match-p "\\.[0-9]+" x)
+ (string-to-number (substring (match-string 0 x) 1))))))
(if (eq var 'eval)
(setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
(if opt
@@ -6759,7 +6754,7 @@ HH:MM."
(not (eq (get-text-property 1 'face s) 'org-link)))
(let* ((h (string-to-number (match-string 1 s)))
(m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
- (ampm (if (match-end 4) (downcase (match-string 4 s))))
+ (ampm (when (match-end 4) (downcase (match-string 4 s))))
(am-p (equal ampm "am"))
(h1 (cond ((not ampm) h)
((= h 12) (if am-p 0 12))
@@ -6836,7 +6831,7 @@ The optional argument TYPE tells the agenda type."
"Limit the number of agenda entries."
(let ((include (and limit (< limit 0))))
(if limit
- (let ((fun (or fn (lambda (p) (if p 1))))
+ (let ((fun (or fn (lambda (p) (when p 1))))
(lim 0))
(delq nil
(mapcar
@@ -6844,7 +6839,7 @@ The optional argument TYPE tells the agenda type."
(let ((pval (funcall
fun (get-text-property (1- (length e))
prop e))))
- (if pval (setq lim (+ lim pval)))
+ (when pval (setq lim (+ lim pval)))
(cond ((and pval (<= lim (abs limit))) e)
((and include (not pval)) e))))
list)))
@@ -6982,14 +6977,14 @@ The optional argument TYPE tells the agenda type."
(tb (and plb (substring b plb)))
(case-fold-search nil))
(when pla
- (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
- "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
- (setq ta (substring ta (match-end 0))))
+ (when (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
+ "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
+ (setq ta (substring ta (match-end 0))))
(setq ta (downcase ta)))
(when plb
- (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
- "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
- (setq tb (substring tb (match-end 0))))
+ (when (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
+ "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
+ (setq tb (substring tb (match-end 0))))
(setq tb (downcase tb)))
(cond ((not ta) +1)
((not tb) -1)
@@ -7087,11 +7082,11 @@ their type."
(alpha-down (if alpha-up (- alpha-up) nil))
(need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
user-defined-up user-defined-down)
- (if (and need-user-cmp org-agenda-cmp-user-defined
- (functionp org-agenda-cmp-user-defined))
- (setq user-defined-up
- (funcall org-agenda-cmp-user-defined a b)
- user-defined-down (if user-defined-up (- user-defined-up) nil)))
+ (when (and need-user-cmp org-agenda-cmp-user-defined
+ (functionp org-agenda-cmp-user-defined))
+ (setq user-defined-up
+ (funcall org-agenda-cmp-user-defined a b)
+ user-defined-down (if user-defined-up (- user-defined-up) nil)))
(cdr (assoc
(eval (cons 'or org-agenda-sorting-strategy-selected))
'((-1 . t) (1 . nil) (nil . nil))))))
@@ -7564,10 +7559,10 @@ also press `-' or `+' to switch between filtering and excluding."
(setq org-agenda-tag-filter nil)
(dolist (tag (org-agenda-get-represented-tags))
(let ((modifier (funcall org-agenda-auto-exclude-function tag)))
- (if modifier
- (push modifier org-agenda-tag-filter))))
- (if (not (null org-agenda-tag-filter))
- (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))))
+ (when modifier
+ (push modifier org-agenda-tag-filter))))
+ (unless (null org-agenda-tag-filter)
+ (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))))
((eq char ?/)
(org-agenda-filter-show-all-tag)
(when (get 'org-agenda-tag-filter :preset-filter)
@@ -7715,7 +7710,7 @@ When NO-OPERATOR is non-nil, do not add the + operator to returned tags."
argument EXPAND can be used for the TYPE tag and will expand the
tags in the FILTER if any of the tags in FILTER are grouptags."
;; Deactivate `org-agenda-entry-text-mode' when filtering
- (if org-agenda-entry-text-mode (org-agenda-entry-text-mode))
+ (when org-agenda-entry-text-mode (org-agenda-entry-text-mode))
(let (tags cat txt)
(setq org-agenda-filter-form (org-agenda-filter-make-matcher filter type expand))
;; Only set `org-agenda-filtered-by-category' to t when a unique
@@ -7732,12 +7727,12 @@ tags in the FILTER if any of the tags in FILTER are grouptags."
(setq tags (org-get-at-bol 'tags)
cat (org-get-at-eol 'org-category 1)
txt (org-get-at-bol 'txt))
- (if (not (eval org-agenda-filter-form))
- (org-agenda-filter-hide-line type))
+ (unless (eval org-agenda-filter-form)
+ (org-agenda-filter-hide-line type))
(beginning-of-line 2))
(beginning-of-line 2))))
- (if (get-char-property (point) 'invisible)
- (ignore-errors (org-agenda-previous-line)))))
+ (when (get-char-property (point) 'invisible)
+ (ignore-errors (org-agenda-previous-line)))))
(defun org-agenda-filter-top-headline-apply (hl &optional negative)
"Filter by top headline HL."
@@ -7747,12 +7742,12 @@ tags in the FILTER if any of the tags in FILTER are grouptags."
(while (not (eobp))
(let* ((pos (org-get-at-bol 'org-hd-marker))
(tophl (and pos (org-find-top-headline pos))))
- (if (and tophl (funcall (if negative 'identity 'not)
- (string= hl tophl)))
- (org-agenda-filter-hide-line 'top-headline)))
+ (when (and tophl (funcall (if negative 'identity 'not)
+ (string= hl tophl)))
+ (org-agenda-filter-hide-line 'top-headline)))
(beginning-of-line 2)))
- (if (get-char-property (point) 'invisible)
- (org-agenda-previous-line))
+ (when (get-char-property (point) 'invisible)
+ (org-agenda-previous-line))
(setq org-agenda-top-headline-filter hl
org-agenda-filtered-by-top-headline t))
@@ -8069,8 +8064,8 @@ SPAN may be `day', `week', `fortnight', `month', `year'."
(org-agenda-check-type t 'agenda)
(let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
(curspan (nth 2 args)))
- (if (and (not n) (equal curspan span))
- (error "Viewing span is already \"%s\"" span))
+ (when (and (not n) (equal curspan span))
+ (error "Viewing span is already \"%s\"" span))
(let* ((sd (or (org-get-at-bol 'day)
(nth 1 args)
org-starting-day))
@@ -8134,11 +8129,10 @@ so that the date SD will be in that range."
(org-agenda-check-type t 'agenda)
(beginning-of-line 1)
;; This does not work if user makes date format that starts with a blank
- (if (looking-at "^\\S-") (forward-char 1))
- (if (not (re-search-forward "^\\S-" nil t arg))
- (progn
- (backward-char 1)
- (error "No next date after this line in this buffer")))
+ (when (looking-at-p "^\\S-") (forward-char 1))
+ (unless (re-search-forward "^\\S-" nil t arg)
+ (backward-char 1)
+ (error "No next date after this line in this buffer"))
(goto-char (match-beginning 0)))
(defun org-agenda-previous-date-line (&optional arg)
@@ -8146,8 +8140,8 @@ so that the date SD will be in that range."
(interactive "p")
(org-agenda-check-type t 'agenda)
(beginning-of-line 1)
- (if (not (re-search-backward "^\\S-" nil t arg))
- (error "No previous date before this line in this buffer")))
+ (unless (re-search-backward "^\\S-" nil t arg)
+ (error "No previous date before this line in this buffer")))
;; Initialize the highlight
(defvar org-hl (make-overlay 1 1))
@@ -8400,7 +8394,7 @@ When called with a prefix argument, include all archive files as well."
(goto (save-excursion
(move-end-of-line 0)
(previous-single-property-change (point) 'org-marker))))
- (if goto (goto-char goto))
+ (when goto (goto-char goto))
(org-move-to-column col)))
(org-agenda-do-context-action))
@@ -8782,8 +8776,8 @@ docstring of `org-agenda-show-1'."
(if (equal org-agenda-cycle-counter 0)
(setq org-agenda-cycle-counter 2)
(setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
- (if (> org-agenda-cycle-counter 3)
- (setq org-agenda-cycle-counter 0)))))
+ (when (> org-agenda-cycle-counter 3)
+ (setq org-agenda-cycle-counter 0)))))
(org-agenda-show-1 org-agenda-cycle-counter))
(defun org-agenda-recenter (arg)
@@ -8802,8 +8796,8 @@ docstring of `org-agenda-show-1'."
(defun org-agenda-check-no-diary ()
"Check if the entry is a diary link and abort if yes."
- (if (org-get-at-bol 'org-agenda-diary-link)
- (org-agenda-error)))
+ (when (org-get-at-bol 'org-agenda-diary-link)
+ (org-agenda-error)))
(defun org-agenda-error ()
"Throw an error when a command is not allowed in the agenda."
@@ -9208,9 +9202,9 @@ Called with a universal prefix arg, show the priority instead of setting it."
cdate (calendar-absolute-from-gregorian
(list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
today (org-today))
- (if (> today cdate)
- ;; immediately shift to today
- (setq arg (- today cdate))))
+ (when (> today cdate)
+ ;; immediately shift to today
+ (setq arg (- today cdate))))
(org-timestamp-change arg (or what 'day))
(when (and (org-at-date-range-p)
(re-search-backward org-tr-regexp-both (point-at-bol)))
@@ -9382,8 +9376,8 @@ buffer, display it in another window."
(interactive)
(let (pos)
(mapc (lambda (o)
- (if (eq (overlay-get o 'type) 'org-agenda-clocking)
- (setq pos (overlay-start o))))
+ (when (eq (overlay-get o 'type) 'org-agenda-clocking)
+ (setq pos (overlay-start o))))
(overlays-in (point-min) (point-max)))
(cond (pos (goto-char pos))
;; If the currently clocked entry is not in the agenda
@@ -9488,19 +9482,19 @@ the resulting entry will not be shown. When TEXT is empty, switch to
(let ((org-prefix-has-time t)
(org-agenda-time-leading-zero t)
fmt time time2)
- (if org-agenda-insert-diary-extract-time
- ;; Use org-agenda-format-item to parse text for a time-range and
- ;; remove it. FIXME: This is a hack, we should refactor
- ;; that function to make time extraction available separately
- (setq fmt (org-agenda-format-item nil text nil nil nil t)
- time (get-text-property 0 'time fmt)
- time2 (if (> (length time) 0)
- ;; split-string removes trailing ...... if
- ;; no end time given. First space
- ;; separates time from date.
- (concat " " (car (split-string time "\\.")))
- nil)
- text (get-text-property 0 'txt fmt)))
+ (when org-agenda-insert-diary-extract-time
+ ;; Use org-agenda-format-item to parse text for a time-range and
+ ;; remove it. FIXME: This is a hack, we should refactor
+ ;; that function to make time extraction available separately
+ (setq fmt (org-agenda-format-item nil text nil nil nil t)
+ time (get-text-property 0 'time fmt)
+ time2 (if (> (length time) 0)
+ ;; split-string removes trailing ...... if
+ ;; no end time given. First space
+ ;; separates time from date.
+ (concat " " (car (split-string time "\\.")))
+ nil)
+ text (get-text-property 0 'txt fmt)))
(if (eq org-agenda-insert-diary-strategy 'top-level)
(org-agenda-insert-diary-as-top-level text)
(require 'org-datetree)
@@ -9783,8 +9777,8 @@ When ARG is greater than one mark ARG lines."
(setq entries-marked (1+ entries-marked))
(call-interactively 'org-agenda-bulk-mark)))))
- (if (not entries-marked)
- (message "No entry matching this regexp."))))
+ (unless entries-marked
+ (message "No entry matching this regexp."))))
(defun org-agenda-bulk-unmark (&optional arg)
"Unmark the entry at point for future bulk action."
@@ -10185,9 +10179,9 @@ details and examples.
If an entry has a APPT_WARNTIME property, its value will be used
to override `appt-message-warning-time'."
(interactive "P")
- (if refresh (setq appt-time-msg-list nil))
- (if (eq filter t)
- (setq filter (read-from-minibuffer "Regexp filter: ")))
+ (when refresh (setq appt-time-msg-list nil))
+ (when (eq filter t)
+ (setq filter (read-from-minibuffer "Regexp filter: ")))
(let* ((cnt 0) ; count added events
(scope (or args '(:deadline* :scheduled* :timestamp)))
(org-agenda-new-buffers nil)