|
| 1 | +;; Copyright (C) 2021 Mariano Montone |
| 2 | + |
| 3 | +;; This program is free software; you can redistribute it and/or modify |
| 4 | +;; it under the terms of the GNU General Public License as published by |
| 5 | +;; the Free Software Foundation, either version 3 of the License, or |
| 6 | +;; (at your option) any later version. |
| 7 | + |
| 8 | +;; This program is distributed in the hope that it will be useful, |
| 9 | +;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | +;; GNU General Public License for more details. |
| 12 | + |
| 13 | +;; You should have received a copy of the GNU General Public License |
| 14 | +;; along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 | + |
| 16 | +;; Install: |
| 17 | +;; Emacs side: just put this file in your load-path and load it on init. |
| 18 | +;; Lisp side: add (require :quicksearch) to your compiler init file (i.e. .sbclrc). |
| 19 | +;; NOTE: |
| 20 | +;; Current quicksearch is buggy for some results. |
| 21 | +;; I recommend you apply this patch: https://github.com/tkych/quicksearch/issues/10 |
| 22 | + |
| 23 | +;; Use: |
| 24 | +;; M-x quicksearch |
| 25 | +;; Customize max results with: M-x customize-variable RET quicksearch-max-results RET |
| 26 | + |
1 | 27 | (require 'slime) |
2 | 28 |
|
| 29 | +(defcustom quicklisp-apropos-max-results 50 |
| 30 | + "Maximum number of results to be returned by quicklisp-apropos.") |
| 31 | + |
| 32 | +;; (defun quicksearch--follow-link (button) |
| 33 | +;; "Follow the URL specified by BUTTON." |
| 34 | +;; (browse-url (button-get button 'url))) |
| 35 | + |
| 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 | + |
| 46 | +;; (define-button-type 'quicksearch-link-button |
| 47 | +;; 'action #'quicksearch--follow-link |
| 48 | +;; 'follow-link t |
| 49 | +;; 'help-echo "Follow this link") |
| 50 | + |
| 51 | +;; (defun quicksearch--propertize-links (string) |
| 52 | +;; "Convert URL links in strings to buttons." |
| 53 | +;; (replace-regexp-in-string |
| 54 | +;; (rx (group (or string-start space "<")) |
| 55 | +;; (group "http" (? "s") "://" (+? (not (any space)))) |
| 56 | +;; (group (? (any "." ">" ")")) |
| 57 | +;; (or space string-end ">"))) |
| 58 | +;; (lambda (match) |
| 59 | +;; (let ((space-before (match-string 1 match)) |
| 60 | +;; (url (match-string 2 match)) |
| 61 | +;; (after (match-string 3 match))) |
| 62 | +;; (concat |
| 63 | +;; space-before |
| 64 | +;; (quicksearch--button |
| 65 | +;; url |
| 66 | +;; 'quicksearch-link-button |
| 67 | +;; 'url url) |
| 68 | +;; after))) |
| 69 | +;; string)) |
| 70 | + |
3 | 71 | (defun quicklisp-apropos (query) |
4 | | - (interactive "s")) |
| 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))) |
| 79 | + (with-current-buffer buffer |
| 80 | + (insert (format "Quicklisp apropos: %s\n\n" query)) |
| 81 | + (insert results) |
| 82 | + (local-set-key "q" 'kill-buffer) |
| 83 | + (setq buffer-read-only t) |
| 84 | + (buffer-disable-undo) |
| 85 | + (goto-char 0) |
| 86 | + (pop-to-buffer buffer)))) |
5 | 87 |
|
6 | 88 | (defun quicklisp-apropos-system (query) |
7 | 89 | (interactive "s")) |
|
24 | 106 | (defun quicklisp-apropos-generic-function (query) |
25 | 107 | (interactive "s")) |
26 | 108 |
|
| 109 | +(define-slime-contrib quicklisp-apropos |
| 110 | + "SLIME extension for running apropos queries across Quicklisp libraries." |
| 111 | + (:swank-dependencies quicklisp-apropos)) |
| 112 | + |
27 | 113 | (provide 'quicklisp-apropos) |
0 commit comments