|
1 | | -;; Copyright (C) 2021 Mariano Montone |
| 1 | +;;; quicklisp-apropos.el --- Commands for quicklisp-apropos -*- lexical-binding: t -*- |
| 2 | + |
| 3 | +;; Copyright (C) 2023 Mariano Montone |
2 | 4 |
|
3 | 5 | ;; This program is free software; you can redistribute it and/or modify |
4 | 6 | ;; it under the terms of the GNU General Public License as published by |
|
29 | 31 | (defcustom quicklisp-apropos-max-results 50 |
30 | 32 | "Maximum number of results to be returned by quicklisp-apropos.") |
31 | 33 |
|
32 | | -;; (defun quicksearch--follow-link (button) |
33 | | -;; "Follow the URL specified by BUTTON." |
34 | | -;; (browse-url (button-get button 'url))) |
| 34 | +(defcustom quicklisp-apropos-query-results-function |
| 35 | + 'quicklisp-apropos--query-results |
| 36 | + "Internal function to use for fetching and showing quicklisp-apropos results.") |
| 37 | + |
35 | 38 |
|
36 | | -;; (defun quicksearch--button (text type &rest properties) |
37 | | -;; ;; `make-text-button' mutates our string to add properties. Copy |
38 | | -;; ;; TEXT to prevent mutating our arguments, and to support 'pure' |
39 | | -;; ;; strings, which are read-only. |
40 | | -;; (setq text (substring-no-properties text)) |
41 | | -;; (apply #'make-text-button |
42 | | -;; text nil |
43 | | -;; :type type |
44 | | -;; properties)) |
45 | 39 |
|
46 | 40 | ;; (define-button-type 'quicksearch-link-button |
47 | 41 | ;; 'action #'quicksearch--follow-link |
|
68 | 62 | ;; after))) |
69 | 63 | ;; string)) |
70 | 64 |
|
71 | | -(defun quicklisp-apropos (query) |
72 | | - (interactive "sQuicklisp apropos: ") |
73 | | - (let* ((results |
74 | | - (slime-eval `(cl:with-output-to-string |
75 | | - (cl:*standard-output*) |
76 | | - (quicklisp-apropos:quicklisp-apropos ,query :count ,quicklisp-apropos-max-results)))) |
77 | | - (buffer-name (format "*quicksearch: %s*" query)) |
78 | | - (buffer (get-buffer-create buffer-name))) |
| 65 | +(defun quicklisp-apropos--open-buffer-with-results (buffer-name results) |
| 66 | + (let ((buffer (get-buffer-create buffer-name))) |
| 67 | + (with-current-buffer buffer |
| 68 | + (dolist (result results) |
| 69 | + (let ((name (cdr (assoc-string "name" result))) |
| 70 | + (type (cdr (assoc-string "type" result))) |
| 71 | + (doc (cdr (assoc-string "doc" result))) |
| 72 | + (system (cdr (assoc-string "system" result)))) |
| 73 | + (insert type) |
| 74 | + (insert " ") |
| 75 | + (insert-button name |
| 76 | + 'follow-link t |
| 77 | + 'help-echo "Load system and edit definition." |
| 78 | + 'action (lambda (_) |
| 79 | + (when (yes-or-no-p (format "Load %s system?" system)) |
| 80 | + (slime-eval `(ql:quickload ,system)) |
| 81 | + (slime-edit-definition name)))) |
| 82 | + (insert " in system ") |
| 83 | + (insert-button system |
| 84 | + 'follow-link t |
| 85 | + 'help-echo "Load system" |
| 86 | + 'action (lambda (_) |
| 87 | + (when (yes-or-no-p (format "Load %s system?" system)) |
| 88 | + (slime-eval `(ql:quickload ,system))))) |
| 89 | + (newline 2) |
| 90 | + (insert doc) |
| 91 | + (newline) |
| 92 | + (insert "--------------------------------------------------------------------------------") |
| 93 | + (newline))) |
| 94 | + (local-set-key "q" 'kill-buffer) |
| 95 | + (setq buffer-read-only t) |
| 96 | + (buffer-disable-undo) |
| 97 | + (goto-char 0) |
| 98 | + (pop-to-buffer buffer)))) |
| 99 | + |
| 100 | +(defun quicklisp-apropos--open-buffer-with-printed-results (buffer-name results) |
| 101 | + (let ((buffer (get-buffer-create buffer-name))) |
79 | 102 | (with-current-buffer buffer |
80 | | - (insert (format "Quicklisp apropos: %s\n\n" query)) |
81 | 103 | (insert results) |
82 | 104 | (local-set-key "q" 'kill-buffer) |
83 | 105 | (setq buffer-read-only t) |
84 | 106 | (buffer-disable-undo) |
85 | 107 | (goto-char 0) |
86 | 108 | (pop-to-buffer buffer)))) |
87 | 109 |
|
| 110 | +(defun quicklisp-apropos--query-printed-results (query) |
| 111 | + (let* ((results |
| 112 | + (slime-eval `(cl:with-output-to-string |
| 113 | + (cl:*standard-output*) |
| 114 | + (quicklisp-apropos:quicklisp-apropos ,query :count ,quicklisp-apropos-max-results)))) |
| 115 | + (buffer-name (format "*quicksearch: %s*" query))) |
| 116 | + (quicklisp-apropos--open-buffer-with-printed-results buffer-name results))) |
| 117 | + |
| 118 | +(defun quicklisp-apropos--query-results (query) |
| 119 | + (let* ((results |
| 120 | + (slime-eval `(quicklisp-apropos:quicklisp-apropos ,query :count ,quicklisp-apropos-max-results :print-results nil))) |
| 121 | + (buffer-name (format "*quicksearch: %s*" query))) |
| 122 | + (quicklisp-apropos--open-buffer-with-results buffer-name |
| 123 | + (mapcar #'car results)))) |
| 124 | + |
| 125 | +(defun quicklisp-apropos (query) |
| 126 | + (interactive "sQuicklisp apropos: ") |
| 127 | + |
| 128 | + (funcall quicklisp-apropos-query-results-function |
| 129 | + query)) |
| 130 | + |
88 | 131 | (defun quicklisp-apropos-system (query) |
89 | 132 | (interactive "s")) |
90 | 133 |
|
|
0 commit comments