[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: The definition of orig-fn.
From: |
Hongyi Zhao |
Subject: |
Re: The definition of orig-fn. |
Date: |
Mon, 4 Oct 2021 20:12:04 +0800 |
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
- The definition of orig-fn., Hongyi Zhao, 2021/10/04
- Re: The definition of orig-fn., Tassilo Horn, 2021/10/04
- Re: The definition of orig-fn.,
Hongyi Zhao <=
- Re: The definition of orig-fn., Tassilo Horn, 2021/10/04
- Re: The definition of orig-fn., Hongyi Zhao, 2021/10/04
- Re: The definition of orig-fn., Tassilo Horn, 2021/10/04
- Re: The definition of orig-fn., Hongyi Zhao, 2021/10/04
- Re: The definition of orig-fn., Tassilo Horn, 2021/10/05
- Re: The definition of orig-fn., Emanuel Berg, 2021/10/05
- Re: The definition of orig-fn., Hongyi Zhao, 2021/10/05
- Re: The definition of orig-fn., Hongyi Zhao, 2021/10/05
- Re: The definition of orig-fn., Tassilo Horn, 2021/10/05
- Re: The definition of orig-fn., Hongyi Zhao, 2021/10/05