Simplify extraction of timeline entries from timeline buffer
This commit is contained in:
parent
e5818fdb8c
commit
3c7ea1b987
|
@ -527,6 +527,20 @@ current values of the relevant buffer local variables."
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(timeline-tools-next-line))))
|
(timeline-tools-next-line))))
|
||||||
|
|
||||||
|
(defun timeline-tools--get-entry-from-point ()
|
||||||
|
"Return timeline entry of point when in timeline buffer."
|
||||||
|
(unless (derived-mode-p 'timeline-tools-mode))
|
||||||
|
(save-mark-and-excursion
|
||||||
|
(unless (org-at-table-p)
|
||||||
|
(user-error "Not in table"))
|
||||||
|
(unless (looking-at "^| ")
|
||||||
|
(user-error "Not on valid row in timeline"))
|
||||||
|
(beginning-of-line)
|
||||||
|
(org-table-next-field)
|
||||||
|
(if-let ((entry (get-text-property (point) 'entry)))
|
||||||
|
entry
|
||||||
|
(user-error "Not on valid row in timeline"))))
|
||||||
|
|
||||||
(defun timeline-tools-next-line ()
|
(defun timeline-tools-next-line ()
|
||||||
"Move point to next line in timetable, if possible."
|
"Move point to next line in timetable, if possible."
|
||||||
(interactive)
|
(interactive)
|
||||||
|
@ -611,13 +625,7 @@ Updates category properties before constructing the new timeline."
|
||||||
(interactive)
|
(interactive)
|
||||||
(unless (eq major-mode 'timeline-tools-mode)
|
(unless (eq major-mode 'timeline-tools-mode)
|
||||||
(user-error "Not in Timeline buffer"))
|
(user-error "Not in Timeline buffer"))
|
||||||
(let ((marker (save-mark-and-excursion
|
(let ((marker (timeline-tools-entry-marker (timeline-tools--get-entry-from-point))))
|
||||||
(beginning-of-line)
|
|
||||||
(org-table-next-field)
|
|
||||||
(-> (get-text-property (point) 'entry)
|
|
||||||
(timeline-tools-entry-marker)))))
|
|
||||||
(unless marker
|
|
||||||
(user-error "Not on headline to jump to"))
|
|
||||||
(switch-to-buffer (marker-buffer marker))
|
(switch-to-buffer (marker-buffer marker))
|
||||||
(goto-char marker)
|
(goto-char marker)
|
||||||
(org-reveal)))
|
(org-reveal)))
|
||||||
|
@ -627,19 +635,15 @@ Updates category properties before constructing the new timeline."
|
||||||
(interactive)
|
(interactive)
|
||||||
(unless (eq major-mode 'timeline-tools-mode)
|
(unless (eq major-mode 'timeline-tools-mode)
|
||||||
(user-error "Not in Timeline buffer"))
|
(user-error "Not in Timeline buffer"))
|
||||||
(save-mark-and-excursion
|
|
||||||
;; get actual entry from headline of line
|
;; If there's an entry on the current line, delete it and redraw; the call to
|
||||||
(beginning-of-line)
|
;; `erase-buffer’ in `timeline-tools-redraw-timeline’ somehow makes
|
||||||
(unless (looking-at "^| ")
|
;; `save-mark-and-excursion’ meaningless; thus we save the number of the
|
||||||
(user-error "Not in table"))
|
|
||||||
(org-table-next-field)
|
|
||||||
(let ((entry (get-text-property (point) 'entry)))
|
|
||||||
(unless entry
|
|
||||||
(user-error "Not on valid row in timeline"))
|
|
||||||
(kill-line)))
|
|
||||||
;; the call to `erase-buffer’ in `timeline-tools-redraw-timeline’ somehow
|
|
||||||
;; makes `save-mark-and-excursion’ meaningless; thus we save the number of the
|
|
||||||
;; current line by ourselves
|
;; current line by ourselves
|
||||||
|
|
||||||
|
(if (timeline-tools--get-entry-from-point) ; barfs if there's no entry
|
||||||
|
(kill-line))
|
||||||
|
|
||||||
(let ((linenum (line-number-at-pos (point))))
|
(let ((linenum (line-number-at-pos (point))))
|
||||||
(timeline-tools-redraw-timeline)
|
(timeline-tools-redraw-timeline)
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
|
@ -659,28 +663,12 @@ changed accordingly."
|
||||||
|
|
||||||
(let (pos-entry-1 pos-entry-2 entry-1 entry-2)
|
(let (pos-entry-1 pos-entry-2 entry-1 entry-2)
|
||||||
|
|
||||||
;; XXX: this feels redundant and should be refactored into a separate
|
|
||||||
;; function or something.
|
|
||||||
(save-mark-and-excursion
|
(save-mark-and-excursion
|
||||||
;; Get first entry and its position.
|
(setq entry-1 (timeline-tools--get-entry-from-point)
|
||||||
(beginning-of-line)
|
|
||||||
(unless (looking-at "^| ")
|
|
||||||
(user-error "Not in table"))
|
|
||||||
(org-table-next-field)
|
|
||||||
(setq entry-1 (get-text-property (point) 'entry)
|
|
||||||
pos-entry-1 (point))
|
pos-entry-1 (point))
|
||||||
(unless entry-1
|
|
||||||
(user-error "Not on valid row in timeline"))
|
|
||||||
|
|
||||||
;; If there's no next line, the following will barf.
|
|
||||||
(timeline-tools-next-line)
|
(timeline-tools-next-line)
|
||||||
|
(setq entry-2 (timeline-tools--get-entry-from-point)
|
||||||
(beginning-of-line)
|
pos-entry-2 (point)))
|
||||||
(org-table-next-field)
|
|
||||||
(setq entry-2 (get-text-property (point) 'entry)
|
|
||||||
pos-entry-2 (point))
|
|
||||||
(unless entry-2
|
|
||||||
(user-error "Next row not valid in timeline")))
|
|
||||||
|
|
||||||
;; Let's create new entries and overwrite the old ones.
|
;; Let's create new entries and overwrite the old ones.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue