Skip to content

Commit c287b6a

Browse files
committed
Load systems and navigate from Emacs
1 parent b8d2b5c commit c287b6a

File tree

1 file changed

+65
-22
lines changed

1 file changed

+65
-22
lines changed

quicklisp-apropos.el

Lines changed: 65 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
;; Copyright (C) 2021 Mariano Montone
1+
;;; quicklisp-apropos.el --- Commands for quicklisp-apropos -*- lexical-binding: t -*-
2+
3+
;; Copyright (C) 2023 Mariano Montone
24

35
;; This program is free software; you can redistribute it and/or modify
46
;; it under the terms of the GNU General Public License as published by
@@ -29,19 +31,11 @@
2931
(defcustom quicklisp-apropos-max-results 50
3032
"Maximum number of results to be returned by quicklisp-apropos.")
3133

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+
3538

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))
4539

4640
;; (define-button-type 'quicksearch-link-button
4741
;; 'action #'quicksearch--follow-link
@@ -68,23 +62,72 @@
6862
;; after)))
6963
;; string))
7064

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)))
79102
(with-current-buffer buffer
80-
(insert (format "Quicklisp apropos: %s\n\n" query))
81103
(insert results)
82104
(local-set-key "q" 'kill-buffer)
83105
(setq buffer-read-only t)
84106
(buffer-disable-undo)
85107
(goto-char 0)
86108
(pop-to-buffer buffer))))
87109

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+
88131
(defun quicklisp-apropos-system (query)
89132
(interactive "s"))
90133

0 commit comments

Comments
 (0)