Bastien <b...@altern.org> writes:

> Nicolas Richard <theonewiththeevill...@yahoo.fr> writes:
>
>> David Griffiths <dogriffi...@gmail.com> writes:
>>> Debugger entered--Lisp error: (error "`recenter'ing a window that does
>>> not display current-buffer.")
>>> recenter((4))
>>> org-overview()
>>
>> So that's a duplicate of #17724. It is fixed in org-mode (upstream) master
>> branch. The easy fix is to use emacs-24 branch :)
>>
>> (otherwise just remove that call to recenter in org-overview).
>
> PS: The change about throwing an error when recentering a window
> that does not display the current buffer breaks ~37 tests in Org
> master branch, even with this fix.  I need to digg this further.

Err, what's the rational behind this change?

In the meantime I've a simple fix (quickly tested for `org-agenda' which
was also broken).

>From 659bc5072253967ee2737f668c8ac035a4b8aa32 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gr=C3=A9goire=20Jadi?= <gregoire.j...@gmail.com>
Date: Thu, 12 Jun 2014 10:14:16 +0900
Subject: [PATCH] Use `org-recenter' as a wrapper around `recenter'

* lisp/org.el (org-recenter): New function that behaves exactly like
`recenter' except that it sets the `current-buffer' to the buffer
displayed by the selected window.

(org-fix-ellipsis-at-bol)
(org-optimize-window-after-visibility-change)
(org-first-headline-recenter)
* contrib/lisp/org-index.el (org-index)
(org-index--create-new-index)
(org-index--do-head)
* contrib/lisp/org-toc.el (org-toc-goto)
* lisp/org-agenda.el (org-agenda-list)
(org-agenda-redo)
(org-recenter-heading)
(org-agenda-recenter)
* lisp/org-bibtex.el (org-execute-file-search-in-bibtex)
* lisp/org-clock.el (org-clock-goto)
* lisp/org-table.el (org-table-show-reference): Use `org-recenter' instead of `recenter'.
---
 contrib/lisp/org-index.el | 12 ++++++------
 contrib/lisp/org-toc.el   |  4 ++--
 lisp/org-agenda.el        | 12 ++++++------
 lisp/org-bibtex.el        |  2 +-
 lisp/org-clock.el         |  2 +-
 lisp/org-table.el         |  4 ++--
 lisp/org.el               | 13 +++++++++----
 7 files changed, 27 insertions(+), 22 deletions(-)

diff --git a/contrib/lisp/org-index.el b/contrib/lisp/org-index.el
index 64974eb..f77d64d 100644
--- a/contrib/lisp/org-index.el
+++ b/contrib/lisp/org-index.el
@@ -633,7 +633,7 @@ command \"head\" for reference \"237\".
       ;; simply go into table
       (goto-char org-index--below-hline)
       (show-subtree)
-      (recenter)
+      (org-recenter)
       (if what-adjusted
           (setq message-text "Nothing to search for; at index table")
         (setq message-text "At index table")))
@@ -1581,7 +1581,7 @@ retrieves the value of the count-column for reference 12.
             (org-id-goto id)
             (org-show-context)    
             (show-subtree)
-            (recenter 1)
+            (org-recenter 1)
             (setq org-index-id id)
             (if (y-or-n-p "This is your new index table. It is already set for this emacs session. Do you want to save its id to make it available for future emacs sessions too ? ")
                 (progn
@@ -1598,7 +1598,7 @@ retrieves the value of the count-column for reference 12.
         (goto-char org-index--point)
         (org-show-context)
         (show-subtree)
-        (recenter 1)
+        (org-recenter 1)
         (delete-other-windows)
         ;; show new index
         (select-window (split-window-vertically))
@@ -1606,7 +1606,7 @@ retrieves the value of the count-column for reference 12.
         (org-id-goto id)
         (org-show-context)    
         (show-subtree)
-        (recenter 1)
+        (org-recenter 1)
         (error "Please compare your existing index (upper window) and a temporary new one (lower window) to correct the previous error (\"%s\"); the explanations following the new index table should help." reason)))))
 
 
@@ -1778,12 +1778,12 @@ retrieves the value of the count-column for reference 12.
                     (pop-to-buffer buffer)
                     (goto-char point)
                     (org-reveal t)
-                    (recenter)
+                    (org-recenter)
                     (pop-to-buffer "*org-index-occur*"))
                 (org-pop-to-buffer-same-window buffer)
                 (goto-char point)
                 (org-reveal t)
-                (recenter)))
+                (org-recenter)))
           (setq message-text (format "Did not find '%s'" (or ref link))))))
     message-text))
 
diff --git a/contrib/lisp/org-toc.el b/contrib/lisp/org-toc.el
index 255b79e..e06de55 100644
--- a/contrib/lisp/org-toc.el
+++ b/contrib/lisp/org-toc.el
@@ -294,8 +294,8 @@ If CYCLE is non-nil, cycle the targeted subtree in the Org window."
 	       (org-show-entry))
 	     (org-show-context)))
     (if org-toc-recenter-mode
-	(if (>= org-toc-recenter 1000) (recenter)
-	  (recenter org-toc-recenter)))
+	(if (>= org-toc-recenter 1000) (org-recenter)
+	  (org-recenter org-toc-recenter)))
     (cond ((null jump)
 	   (switch-to-buffer-other-window toc-buf))
 	  ((eq jump 'delete)
diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 5e056b4..02c583b 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -4348,11 +4348,11 @@ items if they have an hour specification like [h]h:mm."
       (unless (and (pos-visible-in-window-p (point-min))
 		   (pos-visible-in-window-p (point-max)))
 	(goto-char (1- (point-max)))
-	(recenter -1)
+	(org-recenter -1)
 	(if (not (pos-visible-in-window-p (or start-pos 1)))
 	    (progn
 	      (goto-char (or start-pos 1))
-	      (recenter 1))))
+	      (org-recenter 1))))
       (goto-char (or start-pos 1))
       (add-text-properties (point-min) (point-max)
 			   `(org-agenda-type agenda
@@ -7329,7 +7329,7 @@ in the agenda."
     (and top-hl-filter (org-agenda-filter-top-headline-apply top-hl-filter))
     (and cols (org-called-interactively-p 'any) (org-agenda-columns))
     (org-goto-line line)
-    (recenter window-line)))
+    (org-recenter window-line)))
 
 (defvar org-global-tags-completion-table nil)
 (defvar org-agenda-filter-form nil)
@@ -8373,7 +8373,7 @@ When called with a prefix argument, include all archive files as well."
 	     (org-flag-heading nil))))	; show the next heading
     (when (outline-invisible-p)
       (show-entry))			; display invisible text
-    (recenter (/ (window-height) 2))
+    (org-recenter (/ (window-height) 2))
     (org-back-to-heading t)
     (if (re-search-forward org-complex-heading-regexp nil t)
 	(goto-char (match-beginning 4)))
@@ -8697,7 +8697,7 @@ if it was hidden in the outline."
 (defun org-recenter-heading (n)
   (save-excursion
     (org-back-to-heading)
-    (recenter n)))
+    (org-recenter n)))
 
 (defvar org-agenda-cycle-counter nil)
 (defun org-agenda-cycle-show (&optional n)
@@ -8728,7 +8728,7 @@ docstring of `org-agenda-show-1'."
   (interactive "P")
   (let ((win (selected-window)))
     (org-agenda-goto t)
-    (recenter arg)
+    (org-recenter arg)
     (select-window win)))
 
 (defun org-agenda-show-mouse (ev)
diff --git a/lisp/org-bibtex.el b/lisp/org-bibtex.el
index 3efee73..8bcd04e 100644
--- a/lisp/org-bibtex.el
+++ b/lisp/org-bibtex.el
@@ -540,7 +540,7 @@ With optional argument OPTIONAL, also prompt for optional fields."
 	  (with-current-buffer b
 	    (goto-char p)
 	    (bibtex-url)))
-      (recenter 0))  ; Move entry start to beginning of window
+      (org-recenter 0))  ; Move entry start to beginning of window
     ;; return t to indicate that the search is done.
     t))
 
diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index 3c7abd5..9323bd5 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -1702,7 +1702,7 @@ With prefix arg SELECT, offer recently clocked tasks for selection."
     (org-show-entry)
     (org-back-to-heading t)
     (org-cycle-hide-drawers 'children)
-    (recenter org-clock-goto-before-context)
+    (org-recenter org-clock-goto-before-context)
     (org-reveal)
     (if recent
 	(message "No running clock, this is the most recently clocked task"))
diff --git a/lisp/org-table.el b/lisp/org-table.el
index 8cd8f8b..8c9e667 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -3935,9 +3935,9 @@ With prefix ARG, apply the new formulas to the table."
 	(push org-table-current-begin-pos org-show-positions)
 	(let ((min (apply 'min org-show-positions))
 	      (max (apply 'max org-show-positions)))
-	  (goto-char min) (recenter 0)
+	  (goto-char min) (org-recenter 0)
 	  (goto-char max)
-	  (or (pos-visible-in-window-p max) (recenter -1))))
+	  (or (pos-visible-in-window-p max) (org-recenter -1))))
       (select-window win))))
 
 (defun org-table-force-dataline ()
diff --git a/lisp/org.el b/lisp/org.el
index 874440b..b9a81b9 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -5575,7 +5575,7 @@ The following commands are available:
 		    :parents (list text-mode-abbrev-table)))
 
 (defsubst org-fix-ellipsis-at-bol ()
-  (save-excursion (goto-char (window-start)) (recenter 0)))
+  (save-excursion (goto-char (window-start)) (org-recenter 0)))
 
 (defun org-find-invisible-foreground ()
   (let ((candidates (remove
@@ -7059,8 +7059,8 @@ This function is the default value of the hook `org-cycle-hook'."
      ((eq state 'content)  nil)
      ((eq state 'all)      nil)
      ((eq state 'folded)   nil)
-     ((eq state 'children) (or (org-subtree-end-visible-p) (recenter 1)))
-     ((eq state 'subtree)  (or (org-subtree-end-visible-p) (recenter 1))))))
+     ((eq state 'children) (or (org-subtree-end-visible-p) (org-recenter 1)))
+     ((eq state 'subtree)  (or (org-subtree-end-visible-p) (org-recenter 1))))))
 
 (defun org-remove-empty-overlays-at (pos)
   "Remove outline overlays that do not contain non-white stuff."
@@ -7251,7 +7251,7 @@ Optional argument N means put the headline into the Nth line of the window."
   (goto-char (point-min))
   (when (re-search-forward (concat "^\\(" org-outline-regexp "\\)") nil t)
     (beginning-of-line)
-    (recenter (prefix-numeric-value N))))
+    (org-recenter (prefix-numeric-value N))))
 
 ;;; Saving and restoring visibility
 
@@ -23324,6 +23324,11 @@ package ox-bibtex by Taru Karttunen."
     (call-interactively 'reftex-citation)))
 
 ;;;; Functions extending outline functionality
+(defun org-recenter (&optional arg)
+  "Like `recenter' but ensure that the `current-buffer' is
+properly set."
+  (with-current-buffer (window-buffer)
+    (recenter arg)))
 
 (defun org-beginning-of-line (&optional arg)
   "Go to the beginning of the current line.  If that is invisible, continue
-- 
1.8.0.2722.gc0242e5

-- 
Daimrod/Greg

Reply via email to