all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* The definition of orig-fn.
@ 2021-10-04 11:33 Hongyi Zhao
  2021-10-04 11:59 ` Tassilo Horn
  2021-10-04 12:01 ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 2 replies; 23+ messages in thread
From: Hongyi Zhao @ 2021-10-04 11:33 UTC (permalink / raw)
  To: help-gnu-emacs

I'm trying to understand the code snippet here [1] as follows:

;;;
(defun ora--company-good-prefix-p (orig-fn prefix)
(unless (and (stringp prefix) (string-match-p "\\`[0-9]+\\'" prefix))
(funcall orig-fn prefix)))
(ora-advice-add 'company--good-prefix-p :around #'ora--company-good-prefix-p)
;;;

The symbol `orig-fn' used above puzzles me the most. It can't be found
by `C-h o orig-fn RET', and its definition cannot be found elsewhere
in the above repository.

[1] https://github.com/abo-abo/oremacs/blob/3809390019a7083c28e8502a82da94ca3a8ebba0/modes/ora-company.el#L41

Regards, HZ



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

* Re: The definition of orig-fn.
  2021-10-04 11:33 The definition of orig-fn Hongyi Zhao
@ 2021-10-04 11:59 ` Tassilo Horn
  2021-10-04 12:12   ` Hongyi Zhao
  2021-10-04 12:01 ` Emanuel Berg via Users list for the GNU Emacs text editor
  1 sibling, 1 reply; 23+ messages in thread
From: Tassilo Horn @ 2021-10-04 11:59 UTC (permalink / raw)
  To: Hongyi Zhao; +Cc: help-gnu-emacs

Hongyi Zhao <hongyi.zhao@gmail.com> writes:

> I'm trying to understand the code snippet here [1] as follows:
>
> ;;;
> (defun ora--company-good-prefix-p (orig-fn prefix)
> (unless (and (stringp prefix) (string-match-p "\\`[0-9]+\\'" prefix))
> (funcall orig-fn prefix)))
> (ora-advice-add 'company--good-prefix-p :around #'ora--company-good-prefix-p)
> ;;;
>
> The symbol `orig-fn' used above puzzles me the most. It can't be found
> by `C-h o orig-fn RET', and its definition cannot be found elsewhere
> in the above repository.

It's just the first argument of the function and will always be
`company--good-prefix-p' according to the device definition.

Have a look at (info "(elisp) Advice Combinators").

Bye,
Tassilo



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

* Re: The definition of orig-fn.
  2021-10-04 11:33 The definition of orig-fn Hongyi Zhao
  2021-10-04 11:59 ` Tassilo Horn
@ 2021-10-04 12:01 ` Emanuel Berg via Users list for the GNU Emacs text editor
  1 sibling, 0 replies; 23+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-10-04 12:01 UTC (permalink / raw)
  To: help-gnu-emacs

Hongyi Zhao wrote:

> I'm trying to understand the code snippet here [1] as
> follows:
>
> ;;;
> (defun ora--company-good-prefix-p (orig-fn prefix)
> (unless (and (stringp prefix) (string-match-p "\\`[0-9]+\\'" prefix))
> (funcall orig-fn prefix)))
> (ora-advice-add 'company--good-prefix-p :around #'ora--company-good-prefix-p)
> ;;;
>
> The symbol `orig-fn' used above puzzles me the most.
> It can't be found by `C-h o orig-fn RET', and its definition
> cannot be found elsewhere in the above repository.

Formal parameter ...

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: The definition of orig-fn.
  2021-10-04 11:59 ` Tassilo Horn
@ 2021-10-04 12:12   ` Hongyi Zhao
  2021-10-04 12:23     ` Tassilo Horn
  0 siblings, 1 reply; 23+ messages in thread
From: Hongyi Zhao @ 2021-10-04 12:12 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: help-gnu-emacs

On Mon, Oct 4, 2021 at 8:01 PM Tassilo Horn <tsdh@gnu.org> wrote:
>
> Hongyi Zhao <hongyi.zhao@gmail.com> writes:
>
> > I'm trying to understand the code snippet here [1] as follows:
> >
> > ;;;
> > (defun ora--company-good-prefix-p (orig-fn prefix)
> > (unless (and (stringp prefix) (string-match-p "\\`[0-9]+\\'" prefix))
> > (funcall orig-fn prefix)))
> > (ora-advice-add 'company--good-prefix-p :around #'ora--company-good-prefix-p)
> > ;;;
> >
> > The symbol `orig-fn' used above puzzles me the most. It can't be found
> > by `C-h o orig-fn RET', and its definition cannot be found elsewhere
> > in the above repository.
>
> It's just the first argument of the function and will always be
> `company--good-prefix-p' according to the device definition.

Thank you for pointing this out. But I completely commented out the
above code snippet given there [1] as follows, and it still works
smoothly:

  (defun ora-company-number ()
    "Forward to `company-complete-number'.
     Unless the number is potentially part of the candidate.
     In that case, insert the number."
    (interactive)
    (let* ((k (this-command-keys))
           (re (concat "^" company-prefix k)))
      (if (or (cl-find-if (lambda (s) (string-match re s))
                           company-candidates)
              (> (string-to-number k)
                 (length company-candidates))
            (looking-back "[0-9]+\\.[0-9]*" (line-beginning-position)))
        (self-insert-command 1)
        (company-complete-number
        (if (equal k "0") 10
            (string-to-number k))))))

  (let ((map company-active-map))
    (mapc (lambda (x) (define-key map (format "%d" x) 'ora-company-number))
          (number-sequence 0 9)))

[1] https://github.com/abo-abo/oremacs/blob/3809390019a7083c28e8502a82da94ca3a8ebba0/modes/ora-company.el#L22-L53

> Have a look at (info "(elisp) Advice Combinators").

Got it.

Best, HZ



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

* Re: The definition of orig-fn.
  2021-10-04 12:12   ` Hongyi Zhao
@ 2021-10-04 12:23     ` Tassilo Horn
  2021-10-04 13:57       ` Hongyi Zhao
  0 siblings, 1 reply; 23+ messages in thread
From: Tassilo Horn @ 2021-10-04 12:23 UTC (permalink / raw)
  To: Hongyi Zhao; +Cc: help-gnu-emacs

Hongyi Zhao <hongyi.zhao@gmail.com> writes:

>> > (defun ora--company-good-prefix-p (orig-fn prefix)
>> > (unless (and (stringp prefix) (string-match-p "\\`[0-9]+\\'" prefix))
>> > (funcall orig-fn prefix)))
>> > (ora-advice-add 'company--good-prefix-p :around #'ora--company-good-prefix-p)
>> > ;;;
>> >
>> > The symbol `orig-fn' used above puzzles me the most. It can't be found
>> > by `C-h o orig-fn RET', and its definition cannot be found elsewhere
>> > in the above repository.
>>
>> It's just the first argument of the function and will always be
>> `company--good-prefix-p' according to the device definition.
>
> Thank you for pointing this out. But I completely commented out the
> above code snippet given there [1] as follows, and it still works
> smoothly:

Did you also delete the *.el{c,n} files and restart emacs?  When you do
`C-h f company--good-prefix-p RET' it should mention that there is an
advice if there is one.

But I don't understand what you are trying to achieve.  Why are you
commenting that out, and what does "works smoothly" mean in this
context?  (FWIW, I don't use company nor oremacs, so I cannot comment on
that.)

Bye,
Tassilo



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

* Re: The definition of orig-fn.
  2021-10-04 12:23     ` Tassilo Horn
@ 2021-10-04 13:57       ` Hongyi Zhao
  2021-10-04 18:14         ` Tassilo Horn
  0 siblings, 1 reply; 23+ messages in thread
From: Hongyi Zhao @ 2021-10-04 13:57 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 4470 bytes --]

On Mon, Oct 4, 2021 at 8:29 PM Tassilo Horn <tsdh@gnu.org> wrote:
>
> Hongyi Zhao <hongyi.zhao@gmail.com> writes:
>
> >> > (defun ora--company-good-prefix-p (orig-fn prefix)
> >> > (unless (and (stringp prefix) (string-match-p "\\`[0-9]+\\'" prefix))
> >> > (funcall orig-fn prefix)))
> >> > (ora-advice-add 'company--good-prefix-p :around #'ora--company-good-prefix-p)
> >> > ;;;
> >> >
> >> > The symbol `orig-fn' used above puzzles me the most. It can't be found
> >> > by `C-h o orig-fn RET', and its definition cannot be found elsewhere
> >> > in the above repository.
> >>
> >> It's just the first argument of the function and will always be
> >> `company--good-prefix-p' according to the device definition.
> >
> > Thank you for pointing this out. But I completely commented out the
> > above code snippet given there [1] as follows, and it still works
> > smoothly:
>
> Did you also delete the *.el{c,n} files and restart emacs?

I just borrowed the code snippet mentioned here [1] and insert them
into my `~/.emacs.d/init.el' file, and not use the whole oremacs
project as my configuration, as shown below:

;;;
(defun ora-company-number ()
"Forward to `company-complete-number'.

Unless the number is potentially part of the candidate.
In that case, insert the number."
(interactive)
(let* ((k (this-command-keys))
(re (concat "^" company-prefix k)))
(if (or (cl-find-if (lambda (s) (string-match re s))
company-candidates)
(> (string-to-number k)
(length company-candidates))
(looking-back "[0-9]+\\.[0-9]*" (line-beginning-position)))
(self-insert-command 1)
(company-complete-number
(if (equal k "0")
10
(string-to-number k))))))

(defun ora--company-good-prefix-p (orig-fn prefix)
(unless (and (stringp prefix) (string-match-p "\\`[0-9]+\\'" prefix))
(funcall orig-fn prefix)))
(ora-advice-add 'company--good-prefix-p :around #'ora--company-good-prefix-p)

(let ((map company-active-map))
(mapc (lambda (x) (define-key map (format "%d" x) 'ora-company-number))
(number-sequence 0 9))
(define-key map " " (lambda ()
(interactive)
(company-abort)
(self-insert-command 1)))
(define-key map (kbd "<return>") nil))
;;;

In my situation, I can't find the *.el{c,n} files corresponding to
`~/.emacs.d/init.el'.

[1] https://github.com/abo-abo/oremacs/blob/3809390019a7083c28e8502a82da94ca3a8ebba0/modes/ora-company.el#L22-L53

> When you do `C-h f company--good-prefix-p RET' it should mention that there is an
> advice if there is one.

I tried the above command, but only see the following result:

company--good-prefix-p is a compiled function defined in company.el.

Signature
(company--good-prefix-p PREFIX)

Documentation
This function has :around advice: ora--company-good-prefix-p.

References
Finding references in a .el file is not supported.

Find all references

Advice
This function is advised.

Debugging
Enable tracing

Source Code
// Defined in ~/.emacs.d/straight/build/company/company.el
(defun company--good-prefix-p (prefix)
  (and (stringp (company--prefix-str prefix)) ;excludes 'stop
       (or (eq (cdr-safe prefix) t)
           (let ((len (or (cdr-safe prefix) (length prefix))))
             (if company--manual-prefix
                 (or (not company-abort-manual-when-too-short)
                     ;; Must not be less than minimum or initial length.
                     (>= len (min company-minimum-prefix-length
                                  (length company--manual-prefix))))
               (>= len company-minimum-prefix-length))))))

Symbol Properties
defalias-fset-function
  #[128 "\300\301\302 #\207"
    [apply advice--defalias-fset nil nil]
    5 nil]
  Disassemble
function-documentation
  (advice--make-docstring 'company--good-prefix-p)

> But I don't understand what you are trying to achieve.

"Using digits to select company-mode candidates" without hitting the
default modifier key, as noted here [2]. You can see the attachment to
get a rough impression for the purpose of the code snippet discussed
here.

[2] https://oremacs.com/2017/12/27/company-numbers/

> Why are you commenting that out,

Since it seems to me that the remains part of the code has done the
job described there, so I want to simply the original code snippet.

> and what does "works smoothly" mean in this context?

Enables me to select and insert the candidates using digits only,
without hitting the modifier key, which by default is `meta'.

> (FWIW, I don't use company nor oremacs, so I cannot comment on that.)
>
> Bye,
> Tassilo

[-- Attachment #2: company-using-digits-to-select-candidates.png --]
[-- Type: image/png, Size: 120581 bytes --]

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

* Re: The definition of orig-fn.
  2021-10-04 13:57       ` Hongyi Zhao
@ 2021-10-04 18:14         ` Tassilo Horn
  2021-10-05  2:12           ` Hongyi Zhao
  0 siblings, 1 reply; 23+ messages in thread
From: Tassilo Horn @ 2021-10-04 18:14 UTC (permalink / raw)
  To: Hongyi Zhao; +Cc: help-gnu-emacs

Hongyi Zhao <hongyi.zhao@gmail.com> writes:

> I just borrowed the code snippet mentioned here [1] and insert them
> into my `~/.emacs.d/init.el' file, and not use the whole oremacs
> project as my configuration, as shown below:
>
> (defun ora--company-good-prefix-p (orig-fn prefix)
> (unless (and (stringp prefix) (string-match-p "\\`[0-9]+\\'" prefix))
> (funcall orig-fn prefix)))
> (ora-advice-add 'company--good-prefix-p :around #'ora--company-good-prefix-p)

Ok, so you've put the advice definition in your init file, and it seems
you have more "ora" stuff than what you've posted, i.e., you must also
have `ora-advice-add' somewhere if the above doesn't error.

>> When you do `C-h f company--good-prefix-p RET' it should mention that
>> there is an advice if there is one.
>
> I tried the above command, but only see the following result:
>
> company--good-prefix-p is a compiled function defined in company.el.
>
> Signature
> (company--good-prefix-p PREFIX)
>
> Documentation
> This function has :around advice: ora--company-good-prefix-p.
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

There it says that the function is :around-advised with
`ora--company-good-prefix-p'.

>> But I don't understand what you are trying to achieve.
>
> "Using digits to select company-mode candidates" without hitting the
> default modifier key, as noted here [2]. You can see the attachment to
> get a rough impression for the purpose of the code snippet discussed
> here.

Ok.  I somehow lost the contex.  In your first message you've asked what
`orig-fn' is and Emanuel and me told you.  But I can't follow your later
two replies, especially I'm not sure if you are still asking for
help. :-)

Bye,
Tassilo



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

* Re: The definition of orig-fn.
  2021-10-04 18:14         ` Tassilo Horn
@ 2021-10-05  2:12           ` Hongyi Zhao
  2021-10-05  4:56             ` Tassilo Horn
  0 siblings, 1 reply; 23+ messages in thread
From: Hongyi Zhao @ 2021-10-05  2:12 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: help-gnu-emacs

On Tue, Oct 5, 2021 at 2:24 AM Tassilo Horn <tsdh@gnu.org> wrote:
>
> Hongyi Zhao <hongyi.zhao@gmail.com> writes:
>
> > I just borrowed the code snippet mentioned here [1] and insert them
> > into my `~/.emacs.d/init.el' file, and not use the whole oremacs
> > project as my configuration, as shown below:
> >
> > (defun ora--company-good-prefix-p (orig-fn prefix)
> > (unless (and (stringp prefix) (string-match-p "\\`[0-9]+\\'" prefix))
> > (funcall orig-fn prefix)))
> > (ora-advice-add 'company--good-prefix-p :around #'ora--company-good-prefix-p)
>
> Ok, so you've put the advice definition in your init file, and it seems
> you have more "ora" stuff than what you've posted, i.e., you must also
> have `ora-advice-add' somewhere if the above doesn't error.

Yes, I've also borrowed the following code snippet below and put them
immediately above the code snippet which I've posted here in my init
file:

  ;https://github.com/abo-abo/oremacs/blob/d2b2cd8371b94f35a42000debef1c2b644cb9472/init.el#L28
  (defun ora-advice-add (&rest args)
  (when (fboundp 'advice-add)
    (apply #'advice-add args)))


> >> When you do `C-h f company--good-prefix-p RET' it should mention that
> >> there is an advice if there is one.
> >
> > I tried the above command, but only see the following result:
> >
> > company--good-prefix-p is a compiled function defined in company.el.
> >
> > Signature
> > (company--good-prefix-p PREFIX)
> >
> > Documentation
> > This function has :around advice: ora--company-good-prefix-p.
>   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> There it says that the function is :around-advised with
> `ora--company-good-prefix-p'.
>
> >> But I don't understand what you are trying to achieve.
> >
> > "Using digits to select company-mode candidates" without hitting the
> > default modifier key, as noted here [2]. You can see the attachment to
> > get a rough impression for the purpose of the code snippet discussed
> > here.
>
> Ok.  I somehow lost the contex.  In your first message you've asked what
> `orig-fn' is and Emanuel and me told you.  But I can't follow your later
> two replies, especially I'm not sure if you are still asking for
> help. :-)

Basically, I'm asking or trying to figure out the following questions:

1. Whether can I delete out the advice function used in the code
snippet by abo-abo, without affecting the actual function it produces:
Insert the company candidates with digits, unless the number is
potentially part of the candidate; In that case, insert the number.

2. Extend the digits to a more wide range with digits letters, so that
I can select and insert more candidates, as we've discussed here [1].

[1] https://lists.gnu.org/archive/html/help-gnu-emacs/2021-09/msg00527.html

HZ



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

* Re: The definition of orig-fn.
  2021-10-05  2:12           ` Hongyi Zhao
@ 2021-10-05  4:56             ` Tassilo Horn
  2021-10-05  6:06               ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-10-05  6:25               ` Hongyi Zhao
  0 siblings, 2 replies; 23+ messages in thread
From: Tassilo Horn @ 2021-10-05  4:56 UTC (permalink / raw)
  To: Hongyi Zhao; +Cc: help-gnu-emacs

Hongyi Zhao <hongyi.zhao@gmail.com> writes:

>> Ok.  I somehow lost the contex.  In your first message you've asked what
>> `orig-fn' is and Emanuel and me told you.  But I can't follow your later
>> two replies, especially I'm not sure if you are still asking for
>> help. :-)
>
> Basically, I'm asking or trying to figure out the following questions:
>
> 1. Whether can I delete out the advice function used in the code
> snippet by abo-abo, without affecting the actual function it produces:
> Insert the company candidates with digits, unless the number is
> potentially part of the candidate; In that case, insert the number.

I don't know how that candidate selection by number actually works but
the advice arranges that the original `company--good-prefix-p' is only
called if

  (and (stringp prefix) (string-match-p "\\`[0-9]+\\'" prefix))

is nil and that happens only if the prefix doesn't start with a number.
So I'd suggest it's essential to the use-case.

> 2. Extend the digits to a more wide range with digits letters, so that
> I can select and insert more candidates, as we've discussed here [1].

The above regexp would already match 9281 but probably pressing 9
already selects the 9th candidate and you cannot type more?  If that's
the case, I'm out of ideas given that I don't know the code.  But I'd
ask abo-abo, e.g., by opening an issue with your question.

Bye,
Tassilo



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

* Re: The definition of orig-fn.
  2021-10-05  4:56             ` Tassilo Horn
@ 2021-10-05  6:06               ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-10-05  6:25               ` Hongyi Zhao
  1 sibling, 0 replies; 23+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-10-05  6:06 UTC (permalink / raw)
  To: help-gnu-emacs

Tassilo Horn wrote:

> The above regexp would already match 9281 but probably
> pressing 9 already selects the 9th candidate and you cannot
> type more?

Come up with a quote-like syntax e.g. \9281 for 9281 or have
it not do anything until the user presses RET to submit the
indata ... so 9 RET or 9281 RET.

But I don't understand anything either as to the end goal of
all this ...

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: The definition of orig-fn.
  2021-10-05  4:56             ` Tassilo Horn
  2021-10-05  6:06               ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-10-05  6:25               ` Hongyi Zhao
  2021-10-05  6:40                 ` Hongyi Zhao
  2021-10-05  7:32                 ` Tassilo Horn
  1 sibling, 2 replies; 23+ messages in thread
From: Hongyi Zhao @ 2021-10-05  6:25 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: help-gnu-emacs

On Tue, Oct 5, 2021 at 1:01 PM Tassilo Horn <tsdh@gnu.org> wrote:
>
> Hongyi Zhao <hongyi.zhao@gmail.com> writes:
>
> >> Ok.  I somehow lost the contex.  In your first message you've asked what
> >> `orig-fn' is and Emanuel and me told you.  But I can't follow your later
> >> two replies, especially I'm not sure if you are still asking for
> >> help. :-)
> >
> > Basically, I'm asking or trying to figure out the following questions:
> >
> > 1. Whether can I delete out the advice function used in the code
> > snippet by abo-abo, without affecting the actual function it produces:
> > Insert the company candidates with digits, unless the number is
> > potentially part of the candidate; In that case, insert the number.
>
> I don't know how that candidate selection by number actually works but
> the advice arranges that the original `company--good-prefix-p' is only
> called if
>
>   (and (stringp prefix) (string-match-p "\\`[0-9]+\\'" prefix))
>
> is nil and that happens only if the prefix doesn't start with a number.
> So I'd suggest it's essential to the use-case.

Thanks for analyzing the complex advice combination function - if I
could call it that way.

> > 2. Extend the digits to a more wide range with digits letters, so that
> > I can select and insert more candidates, as we've discussed here [1].
>
> The above regexp would already match 9281 but probably pressing 9
> already selects the 9th candidate and you cannot type more?

I still don't quite understand what you mean above. The currently
implemented method can match 0-9, by mapping 0 to 10, therefore, we
can select 10 candidates by number.

> If that's the case, I'm out of ideas given that I don't know the code.  But I'd
> ask abo-abo, e.g., by opening an issue with your question.

Thank you for your suggestion. I'll try to communicate with abo-abo.

HZ



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

* Re: The definition of orig-fn.
  2021-10-05  6:25               ` Hongyi Zhao
@ 2021-10-05  6:40                 ` Hongyi Zhao
  2021-10-05  7:32                 ` Tassilo Horn
  1 sibling, 0 replies; 23+ messages in thread
From: Hongyi Zhao @ 2021-10-05  6:40 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: help-gnu-emacs

On Tue, Oct 5, 2021 at 2:25 PM Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
> Thank you for your suggestion. I'll try to communicate with abo-abo.

I've filed an issue here [1].

[1] https://github.com/abo-abo/oremacs/issues/38

HZ



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

* Re: The definition of orig-fn.
  2021-10-05  6:25               ` Hongyi Zhao
  2021-10-05  6:40                 ` Hongyi Zhao
@ 2021-10-05  7:32                 ` Tassilo Horn
  2021-10-05  8:15                   ` Hongyi Zhao
  1 sibling, 1 reply; 23+ messages in thread
From: Tassilo Horn @ 2021-10-05  7:32 UTC (permalink / raw)
  To: Hongyi Zhao; +Cc: help-gnu-emacs


>> I don't know how that candidate selection by number actually works
>> but the advice arranges that the original `company--good-prefix-p' is
>> only called if
>>
>>   (and (stringp prefix) (string-match-p "\\`[0-9]+\\'" prefix))
>>
>> is nil and that happens only if the prefix doesn't start with a
>> number.  So I'd suggest it's essential to the use-case.
>
> Thanks for analyzing the complex advice combination function - if I
> could call it that way.
>
>> > 2. Extend the digits to a more wide range with digits letters, so that
>> > I can select and insert more candidates, as we've discussed here [1].
>>
>> The above regexp would already match 9281 but probably pressing 9
>> already selects the 9th candidate and you cannot type more?
>
> I still don't quite understand what you mean above. The currently
> implemented method can match 0-9, by mapping 0 to 10, therefore, we
> can select 10 candidates by number.

The advice suppresses calls to `company--good-prefix-p' if the prefix
matches "\\`[0-9]+\\'" which would be true for 9281, too.  That's why
I've said, the regexp would allow multi-digit prefixes but probably the
candidate selection by numeric key press doesn't because it triggers
immediately when a numeric key is pressed.

Bye,
Tassilo



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

* Re: The definition of orig-fn.
  2021-10-05  7:32                 ` Tassilo Horn
@ 2021-10-05  8:15                   ` Hongyi Zhao
  2021-10-05  8:50                     ` Tassilo Horn
  2021-10-05 10:17                     ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 2 replies; 23+ messages in thread
From: Hongyi Zhao @ 2021-10-05  8:15 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: help-gnu-emacs

On Tue, Oct 5, 2021 at 3:47 PM Tassilo Horn <tsdh@gnu.org> wrote:
>
>
> >> I don't know how that candidate selection by number actually works
> >> but the advice arranges that the original `company--good-prefix-p' is
> >> only called if
> >>
> >>   (and (stringp prefix) (string-match-p "\\`[0-9]+\\'" prefix))
> >>
> >> is nil and that happens only if the prefix doesn't start with a
> >> number.  So I'd suggest it's essential to the use-case.
> >
> > Thanks for analyzing the complex advice combination function - if I
> > could call it that way.
> >
> >> > 2. Extend the digits to a more wide range with digits letters, so that
> >> > I can select and insert more candidates, as we've discussed here [1].
> >>
> >> The above regexp would already match 9281 but probably pressing 9
> >> already selects the 9th candidate and you cannot type more?
> >
> > I still don't quite understand what you mean above. The currently
> > implemented method can match 0-9, by mapping 0 to 10, therefore, we
> > can select 10 candidates by number.
>
> The advice suppresses calls to `company--good-prefix-p'

Here [1] comes the definition of `company--good-prefix-p':

(defun company--good-prefix-p (prefix)
(and (stringp (company--prefix-str prefix)) ;excludes 'stop
(or (eq (cdr-safe prefix) t)
(let ((len (or (cdr-safe prefix) (length prefix))))
(if company--manual-prefix
(or (not company-abort-manual-when-too-short)
;; Must not be less than minimum or initial length.
(>= len (min company-minimum-prefix-length
(length company--manual-prefix))))
(>= len company-minimum-prefix-length))))))

[1] https://github.com/company-mode/company-mode/blob/4c08ef468678bbf3b3c9e750f6e694eea1aa8423/company.el#L1974-L1983

> if the prefix matches "\\`[0-9]+\\'" which would be true for 9281, too.

I am puzzled why it is written in this form, to be more specific, why
not just use "[0-9]+"?

> That's why I've said, the regexp would allow multi-digit prefixes

Do you mean that it should be more reasonable by removing the + symbol
in the regexp?

> but probably the candidate selection by numeric key press doesn't because it triggers
> immediately when a numeric key is pressed.

Insertion candidate by a numeric key is for convenience and
efficiency, so it must work the way you described above.

HZ



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

* Re: The definition of orig-fn.
  2021-10-05  8:15                   ` Hongyi Zhao
@ 2021-10-05  8:50                     ` Tassilo Horn
  2021-10-05  9:41                       ` Hongyi Zhao
  2021-10-05 10:17                     ` Emanuel Berg via Users list for the GNU Emacs text editor
  1 sibling, 1 reply; 23+ messages in thread
From: Tassilo Horn @ 2021-10-05  8:50 UTC (permalink / raw)
  To: Hongyi Zhao; +Cc: help-gnu-emacs

Hongyi Zhao <hongyi.zhao@gmail.com> writes:

>> The advice suppresses calls to `company--good-prefix-p'
>
> Here [1] comes the definition of `company--good-prefix-p':

Sorry, I have no time to analyze how company works. ;-)

>> if the prefix matches "\\`[0-9]+\\'" which would be true for 9281, too.
>
> I am puzzled why it is written in this form, to be more specific, why
> not just use "[0-9]+"?

See (info "(elisp) Regexp Backslash"), especially:

--8<---------------cut here---------------start------------->8---
‘\`’
     matches the empty string, but only at the beginning of the buffer
     or string being matched against.

‘\'’
     matches the empty string, but only at the end of the buffer or
     string being matched against.
--8<---------------cut here---------------end--------------->8---

So it only matches if prefix is made up entirely of digits, not if the
prefix contains some digit.

>> That's why I've said, the regexp would allow multi-digit prefixes
>
> Do you mean that it should be more reasonable by removing the + symbol
> in the regexp?

If the selection can only be one single digit, it would make sense.  But
no authorative answer from me who doesn't know the code.  I guess the
author had a reason to add the + there.

>> but probably the candidate selection by numeric key press doesn't
>> because it triggers immediately when a numeric key is pressed.
>
> Insertion candidate by a numeric key is for convenience and
> efficiency, so it must work the way you described above.

No, not necessarily.  One could use prefixes generated by the DeBruijn
sequence, see https://en.wikipedia.org/wiki/De_Bruijn_sequence.

The avy package supports an `avy-style' called `'de-bruijn', and then
you can get unique sequences triggering an action for any alphabet (like
the digits).  Of course, that means that all candidates will get a
"shortcut" of the same length, i.e., with just the letters 0 and 1
available, you could select between 4 candidates using shortcut
sequences 00, 01, 10, and 11.

That's my commit which implemented that for avy:
https://github.com/abo-abo/avy/commit/27b98bb73044cfe61233d065b8f06bd80cf4867b

Bye,
Tassilo




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

* Re: The definition of orig-fn.
  2021-10-05  8:50                     ` Tassilo Horn
@ 2021-10-05  9:41                       ` Hongyi Zhao
  2021-10-05  9:43                         ` Tassilo Horn
  2021-10-05 10:25                         ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 2 replies; 23+ messages in thread
From: Hongyi Zhao @ 2021-10-05  9:41 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: help-gnu-emacs

On Tue, Oct 5, 2021 at 5:10 PM Tassilo Horn <tsdh@gnu.org> wrote:
> >> if the prefix matches "\\`[0-9]+\\'" which would be true for 9281, too.
> >
> > I am puzzled why it is written in this form, to be more specific, why
> > not just use "[0-9]+"?
>
> See (info "(elisp) Regexp Backslash"), especially:
>
> --8<---------------cut here---------------start------------->8---
> ‘\`’
>      matches the empty string, but only at the beginning of the buffer
>      or string being matched against.
>
> ‘\'’
>      matches the empty string, but only at the end of the buffer or
>      string being matched against.
> --8<---------------cut here---------------end--------------->8---
>
> So it only matches if prefix is made up entirely of digits, not if the
> prefix contains some digit.

Thank you for letting me know about these Elisp-specific regexp
metacharacters, I just take it for granted that they are not any
metacharacters.


> >> That's why I've said, the regexp would allow multi-digit prefixes
> >
> > Do you mean that it should be more reasonable by removing the + symbol
> > in the regexp?
>
> If the selection can only be one single digit, it would make sense.  But
> no authorative answer from me who doesn't know the code.  I guess the
> author had a reason to add the + there.
>
> >> but probably the candidate selection by numeric key press doesn't
> >> because it triggers immediately when a numeric key is pressed.
> >
> > Insertion candidate by a numeric key is for convenience and
> > efficiency, so it must work the way you described above.
>
> No, not necessarily.  One could use prefixes generated by the DeBruijn
> sequence, see https://en.wikipedia.org/wiki/De_Bruijn_sequence.
>
> The avy package supports an `avy-style' called `'de-bruijn', and then
> you can get unique sequences triggering an action for any alphabet (like
> the digits).  Of course, that means that all candidates will get a
> "shortcut" of the same length, i.e., with just the letters 0 and 1
> available, you could select between 4 candidates using shortcut
> sequences 00, 01, 10, and 11.

Without further keyboard remapping, this scheme will require at least
two keystrokes to complete a candidate insertion. I think abo-abo's
customized function is just for solving this type of problem: One
keystroke for one candidate insertion.

> That's my commit which implemented that for avy:
> https://github.com/abo-abo/avy/commit/27b98bb73044cfe61233d065b8f06bd80cf4867b

Thank you for letting me know of this interesting feature.

HZ



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

* Re: The definition of orig-fn.
  2021-10-05  9:41                       ` Hongyi Zhao
@ 2021-10-05  9:43                         ` Tassilo Horn
  2021-10-05 10:19                           ` Tassilo Horn
  2021-10-05 10:25                         ` Emanuel Berg via Users list for the GNU Emacs text editor
  1 sibling, 1 reply; 23+ messages in thread
From: Tassilo Horn @ 2021-10-05  9:43 UTC (permalink / raw)
  To: Hongyi Zhao; +Cc: help-gnu-emacs


>> No, not necessarily.  One could use prefixes generated by the DeBruijn
>> sequence, see https://en.wikipedia.org/wiki/De_Bruijn_sequence.
>>
>> The avy package supports an `avy-style' called `'de-bruijn', and then
>> you can get unique sequences triggering an action for any alphabet (like
>> the digits).  Of course, that means that all candidates will get a
>> "shortcut" of the same length, i.e., with just the letters 0 and 1
>> available, you could select between 4 candidates using shortcut
>> sequences 00, 01, 10, and 11.
>
> Without further keyboard remapping, this scheme will require at least
> two keystrokes to complete a candidate insertion. I think abo-abo's
> customized function is just for solving this type of problem: One
> keystroke for one candidate insertion.

Yes, that's a tradeoff.  With De Bruijn, you can make as many candidates
as you need selectable but of course each key sequence becomes longer
the more candidates and the smaller the alphabet (set of keys allowed
for candidate selection).  With just the digits 0-9, you can only make
10 selectable.

Bye,
Tassilo



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

* Re: The definition of orig-fn.
  2021-10-05  8:15                   ` Hongyi Zhao
  2021-10-05  8:50                     ` Tassilo Horn
@ 2021-10-05 10:17                     ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-10-05 11:52                       ` Hongyi Zhao
  1 sibling, 1 reply; 23+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-10-05 10:17 UTC (permalink / raw)
  To: help-gnu-emacs

Hongyi Zhao wrote:

> (eq (cdr-safe prefix) t)

Unidiomatic ...

> (or (eq (cdr-safe prefix) t)
>     (let ((len (or (cdr-safe prefix) [...]

Either illogical or just not good?

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: The definition of orig-fn.
  2021-10-05  9:43                         ` Tassilo Horn
@ 2021-10-05 10:19                           ` Tassilo Horn
  0 siblings, 0 replies; 23+ messages in thread
From: Tassilo Horn @ 2021-10-05 10:19 UTC (permalink / raw)
  Cc: help-gnu-emacs, Hongyi Zhao


>> Without further keyboard remapping, this scheme will require at least
>> two keystrokes to complete a candidate insertion. I think abo-abo's
>> customized function is just for solving this type of problem: One
>> keystroke for one candidate insertion.
>
> Yes, that's a tradeoff.  With De Bruijn, you can make as many
> candidates as you need selectable but of course each key sequence
> becomes longer the more candidates and the smaller the alphabet (set
> of keys allowed for candidate selection).  With just the digits 0-9,
> you can only make 10 selectable.

Just a short correction: you don't need De Bruijn for the former but
arbitrary longer same-length key sequences will do.

The nice property of De Bruijn is that the key sequences overlap nicely
so that, in the context of avy, when jumping to occurrences of the
character x and the word "axxis", it would be annotated by overlays so
that you get

      axxis
       ab    <-- overlay for the first x
        ba   <-- overlay for the second x

which would look like "aabas" in the buffer where the first ab- and
second ba-overlay are fontified distinguishably.  So you have a shortcut
for jumping to each occurrence of x which can be printed correctly
although their annotating overlays overlap because the overlapping part
is equal for both of them.

In the candidate selection for company, De Bruijn is not of importance
because every candidate is shown on its own line anyway so there is no
need to be clever about overlapping parts.

Bye,
Tassilo



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

* Re: The definition of orig-fn.
  2021-10-05  9:41                       ` Hongyi Zhao
  2021-10-05  9:43                         ` Tassilo Horn
@ 2021-10-05 10:25                         ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-10-05 11:55                           ` Hongyi Zhao
  1 sibling, 1 reply; 23+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-10-05 10:25 UTC (permalink / raw)
  To: help-gnu-emacs

Hongyi Zhao wrote:

> Without further keyboard remapping, this scheme will require
> at least two keystrokes to complete a candidate insertion.
> I think abo-abo's customized function is just for solving
> this type of problem: One keystroke for one
> candidate insertion.

I don't know if/how related this is, but take a look at this
[code last - yes, I see I should fix the initial comments ...]

Anyway it works like this, it presents you with shortcuts to
shown alternatives - the shortcuts are ?\r ?\s ?\t ... and
so on.

But if you don't hit a shortcut but instead hit, say, the
letter "l", that letter will be inserted instead.

So if you, for example, have the man page ls(1) open you will
be presented with

  [ RET:ls ]

You can then hit RET to go to the ls man page buffer. But you
can also type "ls" just as you would with

  M-x ls RET

and it doesn't require more keystrokes than that.

Very clever if I may, only bummer was I could never find
another use case but the man pages. A good one by all means
but nonetheless ...

;;; buc.el --- move between buffers based on category -*- lexical-binding: t
;;;
;;; Author: Emanuel Berg (incal) <moasenwood@zoho.eu>
;;; Created: 2021-05-23
;;; Keywords: docs, files
;;; License: GPL3+
;;; Package-Requires: ((cl-lib "1.0"))
;;; URL: https://dataswamp.org/~incal/emacs-init/buc.el
;;; Version: 1.0.4
;;;
;;; Commentary:
;;;
;;; This package enables you to move between similar buffers.
;;; So far I have only found one use case for it, namely
;;; accessing man pages - try `man-buc' below.
;;;
;;; The general idea behind the interface is to present
;;; alternatives based on your recent answers to the same
;;; questions. The alternatives are sorted to present you with
;;; the most relevant one first. You pick an alternative by
;;; hitting a single key. If your desired choice is not among
;;; the alternatives, start typing, that will bypass the
;;; interface and the default interface will be used as
;;; a fallback. (But technically it is not a fallback, rather
;;; the interfaces are cooperating covering different parts of
;;; one problem.)
;;;
;;; Note that If you count the number of keypresses you see
;;; the advantage with this package. When the buc interface is
;;; used, the count is much lower, since making a choice
;;; involves hitting a single key or combination. But even
;;; when it is not used, the count still is not higher than
;;; what you would use anyway, since the default interface
;;; immediately comes to life and utilizes the first keydown
;;; as its first input char. Again, try `man-buc' to see how
;;; it works first hand.
;;;
;;; Or take a look at this screenshot:
;;;
;;;   https://dataswamp.org/~incal/dumps/buc.png
;;;
;;; The principle behind the interface is similar to that of
;;; a computer hardware memory cache: proximity in space and
;;; time, with updates on every single access.
;;;
;;; The interface is an hybrid between the GUI and CLI style,
;;; only the GUI "icons" are here words! Some say icons are
;;; more intuitive than words. Well, that is were we agree to
;;; disagree - perhaps that holds for infants but not to
;;; adults who have spent a HUGE part of their life reading
;;; and writing.
;;;
;;; Because we believe intuition is an acquired skill - just
;;; like everything else.
;;;
;;; Code:

(require 'cl-lib)

(defvar nav-keys     nil "The keys used to select buffers.")
(defvar nav-keys-str nil "Descriptions of the buffer-select keys.")

(setq nav-keys    '(?\r ?\s ?\t ?\d ?\C-j ?\C-k ?\C-l ?\C-u ?\C-o ?\C-p))
(setq nav-keys-str (split-string (key-description nav-keys)))

(defun buffer-names ()
  "Get the names of all open buffers, as strings."
  (mapcar #'buffer-name (buffer-list)) )

(defun extract-strings (strings match)
  "From STRINGS, get a list with the parts that MATCH."
  (remove nil
    (mapcar
     (lambda (s) (when (string-match match s)
                   (match-string 1 s) ))
     strings) ))

(defun get-ps (names)
  "Make the prompt-string, with NAMES."
  (let ((k -1)
        (s " [") )
    (dolist (e names (concat s "] "))
      (setq s (format "%s %s:%s "
                      s (nth (cl-incf k) nav-keys-str) e) ))))

(defun navigate-buffer-category (prefix &optional bad-key &rest args)
  "Display all buffers that start with PREFIX.
If none of the offered buffers are chosen by the user's keystroke,
evaluate (BAD-KEY ARGS)."
  (let ((pages (extract-strings (buffer-names)
                                (format "%s%s" prefix "\\(.*\\)\\*") )))
    (if pages
        (let*((ps         (get-ps pages))
              (key        (read-key ps))
              (page-index (cl-position key nav-keys))
              (page       (when page-index
                            (nth page-index pages)) ))
          (if (= key 7)
              (message "quit")
            (if page
                (switch-to-buffer (format "%s%s*" prefix page))
              (when bad-key
                (apply bad-key `(,@args ,key)) ))))
      (if bad-key
          (apply bad-key args)
        (error "Empty category and no fallback function") ))))

(defun switch-to-type (ps fun &optional key)
  "Ask for a string with the prompt-string PS.
Use the string as input to FUN.
If KEY, it'll be the first KEY of the string, auto-inserted."
  (apply fun
         (list (read-string ps
                            (when key
                              (char-to-string key))
                            nil) )))

(defun man-buc ()
  "Show man pages.
If you start typing, you get the common prompt."
  (interactive)
  (navigate-buffer-category "*Man "
                            #'switch-to-type
                            "[buc] man page: "
                            'man) )

(provide 'buc)
;;; buc.el ends here

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: The definition of orig-fn.
  2021-10-05 10:17                     ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-10-05 11:52                       ` Hongyi Zhao
  0 siblings, 0 replies; 23+ messages in thread
From: Hongyi Zhao @ 2021-10-05 11:52 UTC (permalink / raw)
  To: Emanuel Berg, help-gnu-emacs

On Tue, Oct 5, 2021 at 6:21 PM Emanuel Berg via Users list for the GNU
Emacs text editor <help-gnu-emacs@gnu.org> wrote:
>
> Hongyi Zhao wrote:
>
> > (eq (cdr-safe prefix) t)

Strange. Where did you see the above code written/posted by me? Is it
appeared in this thread? I really don't have any impression about it.

>
> Unidiomatic ...
>
> > (or (eq (cdr-safe prefix) t)
> >     (let ((len (or (cdr-safe prefix) [...]
>
> Either illogical or just not good?

HZ



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

* Re: The definition of orig-fn.
  2021-10-05 10:25                         ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-10-05 11:55                           ` Hongyi Zhao
  2021-10-05 14:21                             ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 23+ messages in thread
From: Hongyi Zhao @ 2021-10-05 11:55 UTC (permalink / raw)
  To: Emanuel Berg, help-gnu-emacs

On Tue, Oct 5, 2021 at 6:26 PM Emanuel Berg via Users list for the GNU
Emacs text editor <help-gnu-emacs@gnu.org> wrote:
>
> Hongyi Zhao wrote:
>
> > Without further keyboard remapping, this scheme will require
> > at least two keystrokes to complete a candidate insertion.
> > I think abo-abo's customized function is just for solving
> > this type of problem: One keystroke for one
> > candidate insertion.
>
> I don't know if/how related this is, but take a look at this
> [code last - yes, I see I should fix the initial comments ...]
>
> Anyway it works like this, it presents you with shortcuts to
> shown alternatives - the shortcuts are ?\r ?\s ?\t ... and
> so on.
>
> But if you don't hit a shortcut but instead hit, say, the
> letter "l", that letter will be inserted instead.
>
> So if you, for example, have the man page ls(1) open you will
> be presented with
>
>   [ RET:ls ]
>
> You can then hit RET to go to the ls man page buffer. But you
> can also type "ls" just as you would with
>
>   M-x ls RET
>
> and it doesn't require more keystrokes than that.
>
> Very clever if I may, only bummer was I could never find
> another use case but the man pages. A good one by all means
> but nonetheless ...
>
> ;;; buc.el --- move between buffers based on category -*- lexical-binding: t
> ;;;
> ;;; Author: Emanuel Berg (incal) <moasenwood@zoho.eu>
> ;;; Created: 2021-05-23
> ;;; Keywords: docs, files
> ;;; License: GPL3+
> ;;; Package-Requires: ((cl-lib "1.0"))
> ;;; URL: https://dataswamp.org/~incal/emacs-init/buc.el
> ;;; Version: 1.0.4
> ;;;
> ;;; Commentary:
> ;;;
> ;;; This package enables you to move between similar buffers.
> ;;; So far I have only found one use case for it, namely
> ;;; accessing man pages - try `man-buc' below.
> ;;;
> ;;; The general idea behind the interface is to present
> ;;; alternatives based on your recent answers to the same
> ;;; questions. The alternatives are sorted to present you with
> ;;; the most relevant one first. You pick an alternative by
> ;;; hitting a single key. If your desired choice is not among
> ;;; the alternatives, start typing, that will bypass the
> ;;; interface and the default interface will be used as
> ;;; a fallback. (But technically it is not a fallback, rather
> ;;; the interfaces are cooperating covering different parts of
> ;;; one problem.)
> ;;;
> ;;; Note that If you count the number of keypresses you see
> ;;; the advantage with this package. When the buc interface is
> ;;; used, the count is much lower, since making a choice
> ;;; involves hitting a single key or combination. But even
> ;;; when it is not used, the count still is not higher than
> ;;; what you would use anyway, since the default interface
> ;;; immediately comes to life and utilizes the first keydown
> ;;; as its first input char. Again, try `man-buc' to see how
> ;;; it works first hand.
> ;;;
> ;;; Or take a look at this screenshot:
> ;;;
> ;;;   https://dataswamp.org/~incal/dumps/buc.png
> ;;;
> ;;; The principle behind the interface is similar to that of
> ;;; a computer hardware memory cache: proximity in space and
> ;;; time, with updates on every single access.
> ;;;
> ;;; The interface is an hybrid between the GUI and CLI style,
> ;;; only the GUI "icons" are here words! Some say icons are
> ;;; more intuitive than words. Well, that is were we agree to
> ;;; disagree - perhaps that holds for infants but not to
> ;;; adults who have spent a HUGE part of their life reading
> ;;; and writing.
> ;;;
> ;;; Because we believe intuition is an acquired skill - just
> ;;; like everything else.
> ;;;
> ;;; Code:
>
> (require 'cl-lib)
>
> (defvar nav-keys     nil "The keys used to select buffers.")
> (defvar nav-keys-str nil "Descriptions of the buffer-select keys.")
>
> (setq nav-keys    '(?\r ?\s ?\t ?\d ?\C-j ?\C-k ?\C-l ?\C-u ?\C-o ?\C-p))
> (setq nav-keys-str (split-string (key-description nav-keys)))
>
> (defun buffer-names ()
>   "Get the names of all open buffers, as strings."
>   (mapcar #'buffer-name (buffer-list)) )
>
> (defun extract-strings (strings match)
>   "From STRINGS, get a list with the parts that MATCH."
>   (remove nil
>     (mapcar
>      (lambda (s) (when (string-match match s)
>                    (match-string 1 s) ))
>      strings) ))
>
> (defun get-ps (names)
>   "Make the prompt-string, with NAMES."
>   (let ((k -1)
>         (s " [") )
>     (dolist (e names (concat s "] "))
>       (setq s (format "%s %s:%s "
>                       s (nth (cl-incf k) nav-keys-str) e) ))))
>
> (defun navigate-buffer-category (prefix &optional bad-key &rest args)
>   "Display all buffers that start with PREFIX.
> If none of the offered buffers are chosen by the user's keystroke,
> evaluate (BAD-KEY ARGS)."
>   (let ((pages (extract-strings (buffer-names)
>                                 (format "%s%s" prefix "\\(.*\\)\\*") )))
>     (if pages
>         (let*((ps         (get-ps pages))
>               (key        (read-key ps))
>               (page-index (cl-position key nav-keys))
>               (page       (when page-index
>                             (nth page-index pages)) ))
>           (if (= key 7)
>               (message "quit")
>             (if page
>                 (switch-to-buffer (format "%s%s*" prefix page))
>               (when bad-key
>                 (apply bad-key `(,@args ,key)) ))))
>       (if bad-key
>           (apply bad-key args)
>         (error "Empty category and no fallback function") ))))
>
> (defun switch-to-type (ps fun &optional key)
>   "Ask for a string with the prompt-string PS.
> Use the string as input to FUN.
> If KEY, it'll be the first KEY of the string, auto-inserted."
>   (apply fun
>          (list (read-string ps
>                             (when key
>                               (char-to-string key))
>                             nil) )))
>
> (defun man-buc ()
>   "Show man pages.
> If you start typing, you get the common prompt."
>   (interactive)
>   (navigate-buffer-category "*Man "
>                             #'switch-to-type
>                             "[buc] man page: "
>                             'man) )
>
> (provide 'buc)
> ;;; buc.el ends here

Apart from expressing my admiration for your research spirit, I also
see no clues that I can use further.

HZ



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

* Re: The definition of orig-fn.
  2021-10-05 11:55                           ` Hongyi Zhao
@ 2021-10-05 14:21                             ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 23+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-10-05 14:21 UTC (permalink / raw)
  To: help-gnu-emacs

Hongyi Zhao wrote:

> Apart from expressing my admiration for your research
> spirit, I also see no clues that I can use further.

If nothing else, is was intended to illustrate that if you put
a shortcut or any kind of idea on top of some other thing with
the intention to make it faster, while it is OK to not succeed
in every use case, if there is a use case when the idea makes
the original thing slower then - well, you don't want that.

-- 
underground experts united
https://dataswamp.org/~incal




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

end of thread, other threads:[~2021-10-05 14:21 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-04 11:33 The definition of orig-fn Hongyi Zhao
2021-10-04 11:59 ` Tassilo Horn
2021-10-04 12:12   ` Hongyi Zhao
2021-10-04 12:23     ` Tassilo Horn
2021-10-04 13:57       ` Hongyi Zhao
2021-10-04 18:14         ` Tassilo Horn
2021-10-05  2:12           ` Hongyi Zhao
2021-10-05  4:56             ` Tassilo Horn
2021-10-05  6:06               ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-05  6:25               ` Hongyi Zhao
2021-10-05  6:40                 ` Hongyi Zhao
2021-10-05  7:32                 ` Tassilo Horn
2021-10-05  8:15                   ` Hongyi Zhao
2021-10-05  8:50                     ` Tassilo Horn
2021-10-05  9:41                       ` Hongyi Zhao
2021-10-05  9:43                         ` Tassilo Horn
2021-10-05 10:19                           ` Tassilo Horn
2021-10-05 10:25                         ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-05 11:55                           ` Hongyi Zhao
2021-10-05 14:21                             ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-05 10:17                     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-05 11:52                       ` Hongyi Zhao
2021-10-04 12:01 ` Emanuel Berg via Users list for the GNU Emacs text editor

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.