Use org-with-wide-buffer where appropriate

* lisp/org-agenda.el (org-agenda-get-some-entry-text):
(org-agenda-refile, org-agenda-open-link):
(org-agenda-change-all-lines, org-agenda-clock-out):
* lisp/org-capture.el (org-capture-refile):
(org-capture-bookmark-last-stored-position):
* lisp/org-clock.el (org-with-clock-position):
(org-clock-in):
* lisp/org-table.el (org-table-recalculate-buffer-tables):
(org-table-iterate-buffer-tables):
* lisp/org.el (org-table-map-tables):
(org-outline-overlay-data, org-refresh-properties):
(org-refresh-stats-properties, org-offer-links-in-entry):
(org-refile, org-refile-check-position):
(org-refile-new-child, org-map-entries):
(org-find-exact-headline-in-buffer):
(org-reftex-citation, org-imenu-get-tree):
Use `org-with-wide-buffer'.
This commit is contained in:
Aaron Ecay 2016-09-03 01:44:58 +01:00
parent 17efe53170
commit ab04bab4d6
5 changed files with 419 additions and 465 deletions

View File

@ -3454,9 +3454,7 @@ removed from the entry content. Currently only `planning' is allowed here."
(with-current-buffer (marker-buffer marker)
(if (not (derived-mode-p 'org-mode))
(setq txt "")
(save-excursion
(save-restriction
(widen)
(org-with-wide-buffer
(goto-char marker)
(end-of-line 1)
(setq txt (buffer-substring
@ -3526,7 +3524,7 @@ removed from the entry content. Currently only `planning' is allowed here."
n-lines)
(org-goto-line (1+ n-lines))
(backward-char 1))
(setq txt (buffer-substring (point-min) (point)))))))))
(setq txt (buffer-substring (point-min) (point))))))))
txt))
(defun org-check-for-org-mode ()
@ -8527,13 +8525,11 @@ When NO-UPDATE is non-nil, don't redo the agenda buffer."
(if goto "Goto" "Refile to") buffer
org-refile-allow-creating-parent-nodes))))
(with-current-buffer buffer
(save-excursion
(save-restriction
(widen)
(org-with-wide-buffer
(goto-char marker)
(let ((org-agenda-buffer-name buffer-orig))
(org-remove-subtree-entries-from-agenda))
(org-refile goto buffer rfloc)))))
(org-refile goto buffer rfloc))))
(unless no-update (org-agenda-redo)))))
(defun org-agenda-open-link (&optional arg)
@ -8558,13 +8554,11 @@ It also looks at the text of the entry itself."
(setq trg (and (string-match org-bracket-link-regexp l)
(match-string 1 l)))
(if (or (not trg) (string-match org-any-link-re trg))
(save-excursion
(save-restriction
(widen)
(org-with-wide-buffer
(goto-char marker)
(when (search-forward l nil lkend)
(goto-char (match-beginning 0))
(org-open-at-point))))
(org-open-at-point)))
;; This is an internal link, widen the buffer
(switch-to-buffer-other-window buffer)
(widen)
@ -8880,9 +8874,9 @@ If FORCE-TAGS is non nil, the car of it returns the new tags."
(line (org-current-line))
(org-agenda-buffer (current-buffer))
(thetags (with-current-buffer (marker-buffer hdmarker)
(save-excursion (save-restriction (widen)
(org-with-wide-buffer
(goto-char hdmarker)
(org-get-tags-at)))))
(org-get-tags-at))))
props m pl undone-face done-face finish new dotime level cat tags)
(save-excursion
(goto-char (point-max))
@ -8903,10 +8897,8 @@ If FORCE-TAGS is non nil, the car of it returns the new tags."
org-prefix-format-compiled))
(extra (org-get-at-bol 'extra)))
(with-current-buffer (marker-buffer hdmarker)
(save-excursion
(save-restriction
(widen)
(org-agenda-format-item extra newhead level cat tags dotime)))))
(org-with-wide-buffer
(org-agenda-format-item extra newhead level cat tags dotime))))
pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
undone-face (org-get-at-bol 'undone-face)
done-face (org-get-at-bol 'done-face))
@ -9297,14 +9289,12 @@ ARG is passed through to `org-deadline'."
(let ((marker (make-marker)) (col (current-column)) newhead)
(org-with-remote-undo (marker-buffer org-clock-marker)
(with-current-buffer (marker-buffer org-clock-marker)
(save-excursion
(save-restriction
(widen)
(org-with-wide-buffer
(goto-char org-clock-marker)
(org-back-to-heading t)
(move-marker marker (point))
(org-clock-out)
(setq newhead (org-get-heading))))))
(setq newhead (org-get-heading)))))
(org-agenda-change-all-lines newhead marker)
(move-marker marker nil)
(org-move-to-column col)

View File

@ -825,11 +825,9 @@ already gone. Any prefix argument will be passed to the refile command."
(org-capture-finalize)
(save-window-excursion
(with-current-buffer (or base (current-buffer))
(save-excursion
(save-restriction
(widen)
(org-with-wide-buffer
(goto-char pos)
(call-interactively 'org-refile)))))
(call-interactively 'org-refile))))
(when kill-buffer (kill-buffer base))))
(defun org-capture-kill ()
@ -1305,16 +1303,14 @@ Of course, if exact position has been required, just put it there."
(point-at-bol))
(point))))))
(with-current-buffer (buffer-base-buffer (current-buffer))
(save-excursion
(save-restriction
(widen)
(org-with-wide-buffer
(goto-char pos)
(let ((bookmark-name (plist-get org-bookmark-names-plist
:last-capture)))
(when bookmark-name
(with-demoted-errors
(bookmark-set bookmark-name))))
(move-marker org-capture-last-stored-marker (point)))))))
(move-marker org-capture-last-stored-marker (point))))))
(defun org-capture-narrow (beg end)
"Narrow, unless configuration says not to narrow."

View File

@ -852,12 +852,10 @@ If CLOCK-SOUND is non-nil, it overrides `org-clock-sound'."
(defmacro org-with-clock-position (clock &rest forms)
"Evaluate FORMS with CLOCK as the current active clock."
`(with-current-buffer (marker-buffer (car ,clock))
(save-excursion
(save-restriction
(widen)
(org-with-wide-buffer
(goto-char (car ,clock))
(beginning-of-line)
,@forms))))
,@forms)))
(def-edebug-spec org-with-clock-position (form body))
(put 'org-with-clock-position 'lisp-indent-function 1)
@ -1252,9 +1250,7 @@ make this the default behavior.)"
(set-buffer (org-base-buffer (marker-buffer selected-task)))
(setq target-pos (marker-position selected-task))
(move-marker selected-task nil))
(save-excursion
(save-restriction
(widen)
(org-with-wide-buffer
(goto-char target-pos)
(org-back-to-heading t)
(or interrupting (move-marker org-clock-interrupted-task nil))
@ -1362,7 +1358,7 @@ make this the default behavior.)"
(setq org-clock-idle-timer
(run-with-timer 60 60 'org-resolve-clocks-if-idle))
(message "Clock starts at %s - %s" ts org--msg-extra)
(run-hooks 'org-clock-in-hook)))))))
(run-hooks 'org-clock-in-hook))))))
;;;###autoload
(defun org-clock-in-last (&optional arg)

View File

@ -3317,10 +3317,8 @@ with the prefix ARG."
(defun org-table-recalculate-buffer-tables ()
"Recalculate all tables in the current buffer."
(interactive)
(save-excursion
(save-restriction
(widen)
(org-table-map-tables (lambda () (org-table-recalculate t)) t))))
(org-with-wide-buffer
(org-table-map-tables (lambda () (org-table-recalculate t)) t)))
;;;###autoload
(defun org-table-iterate-buffer-tables ()
@ -3330,9 +3328,7 @@ with the prefix ARG."
(i imax)
(checksum (md5 (buffer-string)))
c1)
(save-excursion
(save-restriction
(widen)
(org-with-wide-buffer
(catch 'exit
(while (> i 0)
(setq i (1- i))
@ -3342,7 +3338,7 @@ with the prefix ARG."
(message "Convergence after %d iterations" (- imax i))
(throw 'exit t))
(setq checksum c1)))
(user-error "No convergence after %d iterations" imax))))))
(user-error "No convergence after %d iterations" imax)))))
(defun org-table-calc-current-TBLFM (&optional arg)
"Apply the #+TBLFM in the line at point to the table."

View File

@ -4664,9 +4664,7 @@ is nil, return nil unconditionally."
(defun org-table-map-tables (function &optional quietly)
"Apply FUNCTION to the start of all tables in the buffer."
(save-excursion
(save-restriction
(widen)
(org-with-wide-buffer
(goto-char (point-min))
(while (re-search-forward org-table-any-line-regexp nil t)
(unless quietly
@ -4679,7 +4677,7 @@ is nil, return nil unconditionally."
(save-excursion (funcall function))
(or (looking-at org-table-line-regexp)
(forward-char 1)))
(re-search-forward org-table-any-border-regexp nil 1))))
(re-search-forward org-table-any-border-regexp nil 1)))
(unless quietly (message "Mapping tables: done")))
(declare-function org-clock-save-markers-for-cut-and-paste "org-clock" (beg end))
@ -7441,9 +7439,7 @@ The return value is a list of cons cells, with start and stop
positions for each overlay.
If USE-MARKERS is set, return the positions as markers."
(let (beg end)
(save-excursion
(save-restriction
(widen)
(org-with-wide-buffer
(delq nil
(mapcar (lambda (o)
(when (eq (overlay-get o 'invisible) 'outline)
@ -7454,7 +7450,7 @@ If USE-MARKERS is set, return the positions as markers."
(cons (copy-marker beg)
(copy-marker end t))
(cons beg end)))))
(overlays-in (point-min) (point-max))))))))
(overlays-in (point-min) (point-max)))))))
(defun org-set-outline-overlay-data (data)
"Create visibility overlays for all positions in DATA.
@ -9707,12 +9703,10 @@ the value of the drawer property."
(let ((case-fold-search t)
(inhibit-read-only t))
(org-with-silent-modifications
(save-excursion
(save-restriction
(widen)
(org-with-wide-buffer
(goto-char (point-min))
(while (re-search-forward (concat "^[ \t]*:" dprop ": +\\(.*\\)[ \t]*$") nil t)
(org-refresh-property tprop (match-string-no-properties 1))))))))
(org-refresh-property tprop (match-string-no-properties 1)))))))
(defun org-refresh-property (tprop p)
"Refresh the buffer text property TPROP from the drawer property P.
@ -9776,9 +9770,7 @@ The refresh happens only for the current tree (not subtree)."
"Refresh stats text properties in the buffer."
(let (stats)
(org-with-silent-modifications
(save-excursion
(save-restriction
(widen)
(org-with-wide-buffer
(goto-char (point-min))
(while (re-search-forward
(concat org-outline-regexp-bol ".*"
@ -9791,7 +9783,7 @@ The refresh happens only for the current tree (not subtree)."
(t (string-to-number (match-string 1)))))
(org-back-to-heading t)
(put-text-property (point) (progn (org-end-of-subtree t t) (point))
'org-stats stats)))))))
'org-stats stats))))))
(defun org-refresh-effort-properties ()
"Refresh effort properties"
@ -10975,9 +10967,7 @@ If NTH is an integer, return the NTH link found.
If ZERO is a string, check also this string for a link, and if
there is one, return it."
(with-current-buffer buffer
(save-excursion
(save-restriction
(widen)
(org-with-wide-buffer
(goto-char marker)
(let ((cnt ?0)
have-zero end links link c)
@ -11024,7 +11014,7 @@ there is one, return it."
(unless (and (integerp nth) (>= (length links) nth))
(user-error "Invalid link selection"))
(setq link (nth (1- nth) links)))))
(cons link end))))))
(cons link end)))))
;; TODO: These functions are deprecated since `org-open-at-point'
;; hard-codes behaviour for "file+emacs" and "file+sys" types.
@ -12044,9 +12034,7 @@ prefix argument (`C-u C-u C-u C-c C-w')."
(with-current-buffer (setq nbuf (or (find-buffer-visiting file)
(find-file-noselect file)))
(setq reversed (org-notes-order-reversed-p))
(save-excursion
(save-restriction
(widen)
(org-with-wide-buffer
(if pos
(progn
(goto-char pos)
@ -12087,7 +12075,7 @@ prefix argument (`C-u C-u C-u C-c C-w')."
(bookmark-set bookmark-name))))
(move-marker org-capture-last-stored-marker (point)))
(when (fboundp 'deactivate-mark) (deactivate-mark))
(run-hooks 'org-after-refile-insert-hook))))
(run-hooks 'org-after-refile-insert-hook)))
(unless org-refile-keep
(if regionp
(delete-region (point) (+ (point) (- region-end region-start)))
@ -12197,13 +12185,11 @@ this function appends the default value from
(or (find-buffer-visiting file)
(find-file-noselect file))))
(with-current-buffer buffer
(save-excursion
(save-restriction
(widen)
(org-with-wide-buffer
(goto-char pos)
(beginning-of-line 1)
(unless (looking-at-p re)
(user-error "Invalid refile position, please clear the cache with `C-0 C-c C-w' before refiling")))))))))
(user-error "Invalid refile position, please clear the cache with `C-0 C-c C-w' before refiling"))))))))
(defun org-refile-new-child (parent-target child)
"Use refile target PARENT-TARGET to add new CHILD below it."
@ -12214,9 +12200,7 @@ this function appends the default value from
level)
(with-current-buffer (or (find-buffer-visiting file)
(find-file-noselect file))
(save-excursion
(save-restriction
(widen)
(org-with-wide-buffer
(if pos
(goto-char pos)
(goto-char (point-max))
@ -12229,7 +12213,7 @@ this function appends the default value from
(if pos (org-get-valid-level level 1) 1) ?*)
" " child "\n")
(beginning-of-line 0)
(list (concat (car parent-target) "/" child) file "" (point)))))))
(list (concat (car parent-target) "/" child) file "" (point))))))
(defun org-olpath-completing-read (prompt collection &rest args)
"Read an outline path like a file name."
@ -15642,15 +15626,13 @@ a *different* entry, you cannot use these techniques."
(org-agenda-prepare-buffers scope)
(dolist (file scope)
(with-current-buffer (org-find-base-buffer-visiting file)
(save-excursion
(save-restriction
(widen)
(org-with-wide-buffer
(goto-char (point-min))
(setq res
(append
res
(org-scan-tags
func matcher org--matcher-tags-todo-only))))))))))
func matcher org--matcher-tags-todo-only)))))))))
res)))
;;; Properties API
@ -16725,9 +16707,7 @@ If POS-ONLY is set, return just the position instead of a marker.
The heading text must match exact, but it may have a TODO keyword,
a priority cookie and tags in the standard locations."
(with-current-buffer (or buffer (current-buffer))
(save-excursion
(save-restriction
(widen)
(org-with-wide-buffer
(goto-char (point-min))
(let (case-fold-search)
(when (re-search-forward
@ -16735,7 +16715,7 @@ a priority cookie and tags in the standard locations."
(regexp-quote heading)) nil t)
(if pos-only
(match-beginning 0)
(move-marker (make-marker) (match-beginning 0)))))))))
(move-marker (make-marker) (match-beginning 0))))))))
(defun org-find-exact-heading-in-directory (heading &optional dir)
"Find Org node headline HEADING in all .org files in directory DIR.
@ -23784,9 +23764,7 @@ package ox-bibtex by Taru Karttunen."
(let ((reftex-docstruct-symbol 'org--rds)
(reftex-cite-format "\\cite{%l}")
org--rds bib)
(save-excursion
(save-restriction
(widen)
(org-with-wide-buffer
(let ((case-fold-search t)
(re "^[ \t]*#\\+BIBLIOGRAPHY:[ \t]+\\([^ \t\n]+\\)"))
(if (not (save-excursion
@ -23794,7 +23772,7 @@ package ox-bibtex by Taru Karttunen."
(re-search-backward re nil t))))
(user-error "No bibliography defined in file")
(setq bib (concat (match-string 1) ".bib")
org--rds (list (list 'bib bib)))))))
org--rds (list (list 'bib bib))))))
(call-interactively 'reftex-citation)))
;;;; Functions extending outline functionality
@ -24909,9 +24887,7 @@ when non-nil, is a regexp matching keywords names."
(subs (make-vector (1+ n) nil))
(last-level 0)
m level head0 head)
(save-excursion
(save-restriction
(widen)
(org-with-wide-buffer
(goto-char (point-max))
(while (re-search-backward re nil t)
(setq level (org-reduced-level (funcall outline-level)))
@ -24925,7 +24901,7 @@ when non-nil, is a regexp matching keywords names."
(push (cons head m) (aref subs level))
(push (cons head (aref subs (1+ level))) (aref subs level))
(cl-loop for i from (1+ level) to n do (aset subs i nil)))
(setq last-level level)))))
(setq last-level level))))
(aref subs 1)))
(eval-after-load "imenu"