emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[nongnu] elpa/nix-mode 0de9c70c89 429/500: Split up `nix-search` into tw


From: ELPA Syncer
Subject: [nongnu] elpa/nix-mode 0de9c70c89 429/500: Split up `nix-search` into two separate functions
Date: Sat, 29 Jan 2022 08:27:52 -0500 (EST)

branch: elpa/nix-mode
commit 0de9c70c89f23ada6095a6f691d004f7bb661ca1
Author: Daniel Nagy <danielnagy@posteo.de>
Commit: Daniel Nagy <danielnagy@posteo.de>

    Split up `nix-search` into two separate functions
    
    The main intention behind this is that patching the functions should be
    easier. It also allows for experimenting with different displaying
    methods for the search result.
    
    The second argument to the `display` function has been removed in order
    to not dictate how the buffer should be displayed. Users can customize
    this with `display-buffer-alist`.
    
    Also, the fact that the display function is separate allows, for
    example, to store a search result somewhere and have it display later.
---
 nix-search.el | 55 +++++++++++++++++++++++++++----------------------------
 1 file changed, 27 insertions(+), 28 deletions(-)

diff --git a/nix-search.el b/nix-search.el
index 106fe55189..ccd0f03645 100644
--- a/nix-search.el
+++ b/nix-search.el
@@ -17,38 +17,37 @@
 (require 'json)
 
 ;;;###autoload
-(defun nix-search (&optional search file)
+(defun nix-search--search (search file &optional no-cache)
+  (with-temp-buffer
+    (call-process nix-executable nil (list t nil) nil
+      "search" "--json" (if no-cache "--no-cache" "") "--file" file search)
+    (goto-char (point-min))
+    (json-read)))
+
+;;;###autoload
+(defun nix-search--display (results &optional display-buffer)
+  (unless display-buffer (setq display-buffer (generate-new-buffer "*nix 
search*")))
+  (with-current-buffer display-buffer
+    (dolist (entry results)
+      (widget-insert
+        (format "attr: %s\nname: %s\nversion: %s\ndescription: %s\n\n"
+          (car entry)
+          (alist-get 'pkgName (cdr entry))
+          (alist-get 'version (cdr entry))
+          (alist-get 'description (cdr entry))))))
+  (display-buffer display-buffer))
+
+;;;###autoload
+(defun nix-search (search &optional file)
   "Run nix search.
 SEARCH a search term to use.
 FILE a Nix expression to search in."
-  (interactive)
-  (unless search (setq search ""))
-  (unless file (nix-read-file))
-
-  (let ((stdout (generate-new-buffer "nix search"))
-       result)
-    (call-process nix-executable nil (list stdout nil) nil
-                 "search" "--json" "-f" file search)
-    (with-current-buffer stdout
-      (when (eq (buffer-size) 0)
-       (error "Error: nix search %s failed to produce any output" search))
-      (goto-char (point-min))
-      (setq result (json-read)))
-    (kill-buffer stdout)
+  (interactive "snix-search> \n")
+  (setq file (or file (nix-read-file)))
+  (let ((results (nix-search--search search file)))
     (when (called-interactively-p 'any)
-      (let ((display (generate-new-buffer "*nix search*")))
-       (with-current-buffer display
-         (dolist (entry result)
-           (widget-insert
-            (format "attr: %s\nname: %s\nversion: %s\ndescription: %s\n\n"
-                     (car entry)
-                    (alist-get 'pkgName (cdr entry))
-                    (alist-get 'version (cdr entry))
-                    (alist-get 'description (cdr entry)))))
-         )
-       (display-buffer display 'display-buffer-pop-up-window)))
-    (kill-buffer stdout)
-    result))
+      (nix-search--display results))
+    results))
 
 (defun nix-search-read-attr (file)
   "Read from a list of attributes.



reply via email to

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