Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Incremental search of a package

3 views
Skip to first unread message

egarrulo

unread,
Jul 23, 2016, 12:42:21 PM7/23/16
to
To search for a package in the "*Packages*" buffer after M-x
package-show-package-list, I am currently using regular expressions like
this:

1. I start an incremental regexp search;
2. I enter the string "^ " (without quotes) because each line starts
with two spaces followed by the package name;
3. I start to type the name of the package.

Is there a more straightforward way? If not, is it possible to write a
command that performs the steps 1 and 2, so that you only need to start
typing the name of the package?

Thank you.

Emanuel Berg

unread,
Jul 23, 2016, 4:09:26 PM7/23/16
to
egarrulo wrote:

> Is there a more straightforward way? If not,
> is it possible to write a command that
> performs the steps 1 and 2, so that you only
> need to start typing the name of the package?

... why can't you just do that?

--
underground experts united .... http://user.it.uu.se/~embe8573
Emacs Gnus Blogomatic ......... http://user.it.uu.se/~embe8573/blogomatic
- so far: 58 Blogomatic articles -

egarrulo

unread,
Jul 23, 2016, 5:33:37 PM7/23/16
to
On 23/07/16 22:09, Emanuel Berg wrote:
> egarrulo wrote:
>
>> Is there a more straightforward way? If not,
>> is it possible to write a command that
>> performs the steps 1 and 2, so that you only
>> need to start typing the name of the package?
>
> ... why can't you just do that?

I have tried, but the following code makes Emacs loop on an error
(therefore save your work before trying it):

(defun isearch-forward-package ()
(interactive)
(add-hook 'isearch-mode-hook 'yank-package-line-regexp nil t)
(unwind-protect
(isearch-forward-regexp)
(remove-hook 'isearch-mode-hook 'yank-package-line-regexp t)))

(defun yank-package-line-regexp ()
(isearch-yank-string "^ "))

Emanuel Berg

unread,
Jul 23, 2016, 5:55:34 PM7/23/16
to
egarrulo wrote:

> I have tried, but the following code makes
> Emacs loop on an error (therefore save your
> work before trying it):
>
> (defun isearch-forward-package ()
> (interactive)
> (add-hook 'isearch-mode-hook 'yank-package-line-regexp nil t)
> (unwind-protect
> (isearch-forward-regexp)
> (remove-hook 'isearch-mode-hook 'yank-package-line-regexp t)))
>
> (defun yank-package-line-regexp ()
> (isearch-yank-string "^ "))

No, I mean, why can't you just search for the
package name? Without any additional Elisp?

Otherwise I'd doe something like this:

(defun search-package (pack)
(interactive "sPackage: ")
(let ((regexp (format "^ %s" pack)))
(if (search-forward-regexp regexp (point-max) t) ; NOERROR
(back-to-indentation)
(message "No package: %s" pack) )))

Emanuel Berg

unread,
Jul 23, 2016, 6:10:35 PM7/23/16
to
A better (?) version of what I just wrote:

(defun search-package (pack)
(interactive "sPackage: ")
(let*((regexp (format "^ %s" pack))
(hit (save-excursion
(goto-char (point-min))
(when (search-forward-regexp regexp (point-max) t)
(back-to-indentation)
(point) ))))
(if hit (goto-char hit)
(message "No package: %s" pack) )))

0 new messages