[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.
- [nongnu] elpa/nix-mode 241cc0881e 466/500: nix-flake.el: Init nix-flake command, (continued)
- [nongnu] elpa/nix-mode 241cc0881e 466/500: nix-flake.el: Init nix-flake command, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode dd0d1c0d0b 467/500: nix-flake: WIP: nix-flake-init, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode acf4fd09db 470/500: nix-flake: Add customization options, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 7346057087 471/500: nix-flake: Show aliases in the registry as well, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode de85646434 486/500: Add dependabot.yml, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 186698599c 480/500: nix-flake: Set a prompt string, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 6712a66321 381/500: Fix yaml, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 1c42c634bf 379/500: Allow missing git repo, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 38958e5203 413/500: Update install-nix-action in GitHub Action, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode cc60a0d027 417/500: Make nix-drv-mode a derived-mode of javascript-mode, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 0de9c70c89 429/500: Split up `nix-search` into two separate functions,
ELPA Syncer <=
- [nongnu] elpa/nix-mode e8e5211f6e 426/500: Merge pull request #122 from leungbk/def-obsol, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 98426b94e5 280/500: Add function to indent things in blocks for nix-indent-line, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 71fda1db41 373/500: add README section for nix-prettify-mode (#100), ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode fc68739bec 011/500: Fix syntax error, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode cb392d45b6 030/500: tweak indentation, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode ade1d49841 128/500: Fixup indentation logic., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 414a40fe54 131/500: Add hydra mode (#25), ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode f7fa332705 155/500: Add nix-shell custom group, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 6573b1d70e 145/500: Add nix-shell.el, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 0af6073003 171/500: Add nix-mode to nix-mode group., ELPA Syncer, 2022/01/29