guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

22/35: emacs: Generalize buffer redisplaying.


From: Alex Kost
Subject: 22/35: emacs: Generalize buffer redisplaying.
Date: Fri, 11 Dec 2015 11:42:38 +0000

alezost pushed a commit to branch wip-refactor-emacs-ui
in repository guix.

commit b9aae5c9464a89983f4ef13b8080dc71dd45c04c
Author: Alex Kost <address@hidden>
Date:   Sun Nov 22 13:21:18 2015 +0300

    emacs: Generalize buffer redisplaying.
    
    * emacs/guix-base.el (guix-buffer-after-redisplay-hook): New variable.
      (guix-redisplay-buffer): Use it.  Remove all arguments and the code
      for moving point to the next button.  Rename to...
      (guix-buffer-redisplay): ... this.
      (guix-buffer-redisplay-goto-button): New procedure.
    * emacs/guix-info.el (guix-package-info-show-source): Use it.  Adjust
      accordingly.
      (guix-package-info-redisplay-after-download): Likewise.
---
 emacs/guix-base.el |   64 +++++++++++++++++++++++++--------------------------
 emacs/guix-info.el |   15 +++++++-----
 2 files changed, 40 insertions(+), 39 deletions(-)

diff --git a/emacs/guix-base.el b/emacs/guix-base.el
index 73c9404..7592988 100644
--- a/emacs/guix-base.el
+++ b/emacs/guix-base.el
@@ -288,7 +288,7 @@ This alist is filled by `guix-buffer-define-interface' 
macro.")
     (define-key map (kbd "l") 'guix-history-back)
     (define-key map (kbd "r") 'guix-history-forward)
     (define-key map (kbd "g") 'revert-buffer)
-    (define-key map (kbd "R") 'guix-redisplay-buffer)
+    (define-key map (kbd "R") 'guix-buffer-redisplay)
     map)
   "Parent keymap for Guix buffer modes.")
 
@@ -616,41 +616,39 @@ See `revert-buffer' for the meaning of NOCONFIRM."
       (guix-set-buffer guix-profile entries guix-buffer-type guix-entry-type
                        search-type search-vals t t))))
 
-(cl-defun guix-redisplay-buffer (&key buffer profile entries buffer-type
-                                      entry-type search-type search-vals)
-  "Redisplay a Guix BUFFER.
-Restore the point and window positions after redisplaying if possible.
+(defvar guix-buffer-after-redisplay-hook nil
+  "Hook run by `guix-buffer-redisplay'.
+This hook is called before seting up a window position.")
 
-This function will not update the information, use
-\"\\[revert-buffer]\" if you want the full update.
+(defun guix-buffer-redisplay ()
+  "Redisplay the current Guix buffer.
+Restore the point and window positions after redisplaying.
 
-If BUFFER is nil, use the current buffer.  For the meaning of the
-rest arguments, see `guix-set-buffer'."
+This function does not update the buffer data, use
+'\\[revert-buffer]' if you want the full update."
   (interactive)
-  (or buffer (setq buffer (current-buffer)))
-  (with-current-buffer buffer
-    (or (derived-mode-p 'guix-info-mode 'guix-list-mode)
-        (error "%S is not a Guix buffer" buffer))
-    (let* ((point (point))
-           (was-at-button (button-at point))
-           ;; For simplicity, ignore an unlikely case when multiple
-           ;; windows display the same BUFFER.
-           (window (car (get-buffer-window-list buffer nil t)))
-           (window-start (and window (window-start window))))
-      (guix-set-buffer (or profile     guix-profile)
-                       (or entries     guix-entries)
-                       (or buffer-type guix-buffer-type)
-                       (or entry-type  guix-entry-type)
-                       (or search-type guix-search-type)
-                       (or search-vals guix-search-vals)
-                       t t)
-      (goto-char point)
-      (and was-at-button
-           (not (button-at (point)))
-           (forward-button 1))
-      (when window
-        (set-window-point window (point))
-        (set-window-start window window-start)))))
+  (let* ((old-point (point))
+         ;; For simplicity, ignore an unlikely case when multiple
+         ;; windows display the same buffer.
+         (window (car (get-buffer-window-list (current-buffer) nil t)))
+         (window-start (and window (window-start window))))
+    (guix-set-buffer guix-profile guix-entries guix-buffer-type
+                     guix-entry-type guix-search-type guix-search-vals
+                     t t)
+    (goto-char old-point)
+    (run-hooks 'guix-buffer-after-redisplay-hook)
+    (when window
+      (set-window-point window (point))
+      (set-window-start window window-start))))
+
+(defun guix-buffer-redisplay-goto-button ()
+  "Redisplay the current buffer and go to the next button, if needed."
+  (let ((guix-buffer-after-redisplay-hook
+         (cons (lambda ()
+                 (unless (button-at (point))
+                   (forward-button 1)))
+               guix-buffer-after-redisplay-hook)))
+    (guix-buffer-redisplay)))
 
 
 ;;; Generations
diff --git a/emacs/guix-info.el b/emacs/guix-info.el
index c988d9c..a9f7bd8 100644
--- a/emacs/guix-info.el
+++ b/emacs/guix-info.el
@@ -710,14 +710,16 @@ prompt depending on `guix-operation-confirm' variable)."
 Find the file if needed (see `guix-package-info-auto-find-source').
 ENTRY-ID is an ID of the current entry (package or output).
 PACKAGE-ID is an ID of the package which source to show."
-  (let* ((entry (guix-entry-by-id entry-id guix-entries))
-         (file  (guix-package-source-path package-id)))
+  (let* ((entries guix-entries)
+         (entry   (guix-entry-by-id entry-id guix-entries))
+         (file    (guix-package-source-path package-id)))
     (or file
-        (error "Couldn't define file path of the package source"))
+        (error "Couldn't define file name of the package source"))
     (let* ((new-entry (cons (cons 'source-file file)
                             entry))
-           (entries (guix-replace-entry entry-id new-entry guix-entries)))
-      (guix-redisplay-buffer :entries entries)
+           (new-entries (guix-replace-entry entry-id new-entry entries)))
+      (setq guix-entries new-entries)
+      (guix-buffer-redisplay-goto-button)
       (if (file-exists-p file)
           (if guix-package-info-auto-find-source
               (guix-find-file file)
@@ -766,7 +768,8 @@ SOURCE is a list of URLs."
   "Redisplay an 'info' buffer after downloading the package source.
 This function is used to hide a \"Download\" button if needed."
   (when (buffer-live-p guix-package-info-download-buffer)
-    (guix-redisplay-buffer :buffer guix-package-info-download-buffer)
+    (with-current-buffer guix-package-info-download-buffer
+      (guix-buffer-redisplay-goto-button))
     (setq guix-package-info-download-buffer nil)))
 
 (add-hook 'guix-after-source-download-hook



reply via email to

[Prev in Thread] Current Thread [Next in Thread]