unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Incremental search of a package
@ 2016-07-23 16:42 egarrulo
  2016-07-23 20:09 ` Emanuel Berg
  0 siblings, 1 reply; 5+ messages in thread
From: egarrulo @ 2016-07-23 16:42 UTC (permalink / raw)
  To: help-gnu-emacs

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.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Incremental search of a package
  2016-07-23 16:42 Incremental search of a package egarrulo
@ 2016-07-23 20:09 ` Emanuel Berg
  2016-07-23 21:33   ` egarrulo
  0 siblings, 1 reply; 5+ messages in thread
From: Emanuel Berg @ 2016-07-23 20:09 UTC (permalink / raw)
  To: help-gnu-emacs

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 -                   


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Incremental search of a package
  2016-07-23 20:09 ` Emanuel Berg
@ 2016-07-23 21:33   ` egarrulo
  2016-07-23 21:55     ` Emanuel Berg
  2016-07-23 22:10     ` Emanuel Berg
  0 siblings, 2 replies; 5+ messages in thread
From: egarrulo @ 2016-07-23 21:33 UTC (permalink / raw)
  To: help-gnu-emacs

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 "^  "))


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Incremental search of a package
  2016-07-23 21:33   ` egarrulo
@ 2016-07-23 21:55     ` Emanuel Berg
  2016-07-23 22:10     ` Emanuel Berg
  1 sibling, 0 replies; 5+ messages in thread
From: Emanuel Berg @ 2016-07-23 21:55 UTC (permalink / raw)
  To: help-gnu-emacs

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

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Incremental search of a package
  2016-07-23 21:33   ` egarrulo
  2016-07-23 21:55     ` Emanuel Berg
@ 2016-07-23 22:10     ` Emanuel Berg
  1 sibling, 0 replies; 5+ messages in thread
From: Emanuel Berg @ 2016-07-23 22:10 UTC (permalink / raw)
  To: help-gnu-emacs

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

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-07-23 22:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-23 16:42 Incremental search of a package egarrulo
2016-07-23 20:09 ` Emanuel Berg
2016-07-23 21:33   ` egarrulo
2016-07-23 21:55     ` Emanuel Berg
2016-07-23 22:10     ` Emanuel Berg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).