all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Re: master 5892b4db8de 2/3: Convert dictionary-mode to define-derived-mode
       [not found] ` <20230812145313.C853CC038C2@vcs2.savannah.gnu.org>
@ 2023-08-16 12:55   ` Visuwesh
  2023-08-16 19:45     ` Stefan Kangas
                       ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Visuwesh @ 2023-08-16 12:55 UTC (permalink / raw)
  To: emacs-devel; +Cc: Stefan Kangas

[சனி ஆகஸ்ட் 12, 2023] Stefan Kangas wrote:

> branch: master
> commit 5892b4db8de4694904f631dd86438926fb9d7ff1
> Author: Stefan Kangas <stefankangas@gmail.com>
> Commit: Stefan Kangas <stefankangas@gmail.com>
>
>     Convert dictionary-mode to define-derived-mode
>     
>     * lisp/net/dictionary.el (dictionary-instances): Delete.
>     (dictionary-mode): Use define-derived-mode.
>     (dictionary--count-mode-buffers): New function.
>     (dictionary-close): Use above new function.
 
> +(defun dictionary--count-mode-buffers ()
> +  "Return the number of buffers that "

The docstring is incomplete here.  :-(

> +  (seq-reduce #'+
> +              (mapcar
> +               (lambda (buf)
> +                 (with-current-buffer buf
> +                   (if (derived-mode-p 'dictionary-mode) 1 0)))
> +               (buffer-list))
> +              0))
> +

I believe the following function should be faster

    (defun dictionary--count-mode-buffers ()
      "Return the number of buffers that "
      (seq-reduce (lambda (count buf)
                    (if (provided-mode-derived-p (buffer-local-value 'major-mode buf)
                                                 'dictionary-mode)
                        (+ count 1)
                      count))
                  (buffer-list)
                  0))



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

* Re: master 5892b4db8de 2/3: Convert dictionary-mode to define-derived-mode
  2023-08-16 12:55   ` master 5892b4db8de 2/3: Convert dictionary-mode to define-derived-mode Visuwesh
@ 2023-08-16 19:45     ` Stefan Kangas
  2023-08-16 22:33     ` Philip Kaludercic
  2023-08-17  9:15     ` Basil L. Contovounesios
  2 siblings, 0 replies; 6+ messages in thread
From: Stefan Kangas @ 2023-08-16 19:45 UTC (permalink / raw)
  To: Visuwesh; +Cc: emacs-devel

Visuwesh <visuweshm@gmail.com> writes:

> I believe the following function should be faster
>
>     (defun dictionary--count-mode-buffers ()
>       "Return the number of buffers that "
>       (seq-reduce (lambda (count buf)
>                     (if (provided-mode-derived-p (buffer-local-value 'major-mode buf)
>                                                  'dictionary-mode)
>                         (+ count 1)
>                       count))
>                   (buffer-list)
>                   0))

Thanks, pushed to master (commit d96dd127e39).



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

* Re: master 5892b4db8de 2/3: Convert dictionary-mode to define-derived-mode
  2023-08-16 12:55   ` master 5892b4db8de 2/3: Convert dictionary-mode to define-derived-mode Visuwesh
  2023-08-16 19:45     ` Stefan Kangas
@ 2023-08-16 22:33     ` Philip Kaludercic
  2023-08-19 11:08       ` Stefan Kangas
  2023-08-17  9:15     ` Basil L. Contovounesios
  2 siblings, 1 reply; 6+ messages in thread
From: Philip Kaludercic @ 2023-08-16 22:33 UTC (permalink / raw)
  To: Visuwesh; +Cc: emacs-devel, Stefan Kangas

Visuwesh <visuweshm@gmail.com> writes:

> [சனி ஆகஸ்ட் 12, 2023] Stefan Kangas wrote:
>
>> branch: master
>> commit 5892b4db8de4694904f631dd86438926fb9d7ff1
>> Author: Stefan Kangas <stefankangas@gmail.com>
>> Commit: Stefan Kangas <stefankangas@gmail.com>
>>
>>     Convert dictionary-mode to define-derived-mode
>>     
>>     * lisp/net/dictionary.el (dictionary-instances): Delete.
>>     (dictionary-mode): Use define-derived-mode.
>>     (dictionary--count-mode-buffers): New function.
>>     (dictionary-close): Use above new function.
>  
>> +(defun dictionary--count-mode-buffers ()
>> +  "Return the number of buffers that "
>
> The docstring is incomplete here.  :-(
>
>> +  (seq-reduce #'+
>> +              (mapcar
>> +               (lambda (buf)
>> +                 (with-current-buffer buf
>> +                   (if (derived-mode-p 'dictionary-mode) 1 0)))
>> +               (buffer-list))
>> +              0))
>> +
>
> I believe the following function should be faster
>
>     (defun dictionary--count-mode-buffers ()
>       "Return the number of buffers that "
>       (seq-reduce (lambda (count buf)
>                     (if (provided-mode-derived-p (buffer-local-value 'major-mode buf)
>                                                  'dictionary-mode)
>                         (+ count 1)
>                       count))
>                   (buffer-list)
>                   0))

Alternatively (length (match-buffers '(derived-mode . dictionary-mode)))



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

* Re: master 5892b4db8de 2/3: Convert dictionary-mode to define-derived-mode
  2023-08-16 12:55   ` master 5892b4db8de 2/3: Convert dictionary-mode to define-derived-mode Visuwesh
  2023-08-16 19:45     ` Stefan Kangas
  2023-08-16 22:33     ` Philip Kaludercic
@ 2023-08-17  9:15     ` Basil L. Contovounesios
  2 siblings, 0 replies; 6+ messages in thread
From: Basil L. Contovounesios @ 2023-08-17  9:15 UTC (permalink / raw)
  To: Visuwesh; +Cc: emacs-devel, Stefan Kangas

Visuwesh [2023-08-16 18:25 +0530] wrote:

> [சனி ஆகஸ்ட் 12, 2023] Stefan Kangas wrote:
>
>> branch: master
>> commit 5892b4db8de4694904f631dd86438926fb9d7ff1
>> Author: Stefan Kangas <stefankangas@gmail.com>
>> Commit: Stefan Kangas <stefankangas@gmail.com>
>>
>> +  (seq-reduce #'+
>> +              (mapcar
>> +               (lambda (buf)
>> +                 (with-current-buffer buf
>> +                   (if (derived-mode-p 'dictionary-mode) 1 0)))
>> +               (buffer-list))
>> +              0))
>> +
>
> I believe the following function should be faster
>
>     (defun dictionary--count-mode-buffers ()
>       "Return the number of buffers that "
>       (seq-reduce (lambda (count buf)
>                     (if (provided-mode-derived-p (buffer-local-value 'major-mode buf)
>                                                  'dictionary-mode)
>                         (+ count 1)
>                       count))
>                   (buffer-list)
>                   0))

Yet faster and simpler would be to use seq-count in place of seq-reduce.

Thanks,
-- 
Basil



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

* Re: master 5892b4db8de 2/3: Convert dictionary-mode to define-derived-mode
  2023-08-16 22:33     ` Philip Kaludercic
@ 2023-08-19 11:08       ` Stefan Kangas
  2023-08-19 15:46         ` Philip Kaludercic
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Kangas @ 2023-08-19 11:08 UTC (permalink / raw)
  To: Philip Kaludercic; +Cc: Visuwesh, emacs-devel

Philip Kaludercic <philipk@posteo.net>:

> Alternatively (length (match-buffers '(derived-mode . dictionary-mode)))

Nice golfing, thanks.  I installed that.



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

* Re: master 5892b4db8de 2/3: Convert dictionary-mode to define-derived-mode
  2023-08-19 11:08       ` Stefan Kangas
@ 2023-08-19 15:46         ` Philip Kaludercic
  0 siblings, 0 replies; 6+ messages in thread
From: Philip Kaludercic @ 2023-08-19 15:46 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: Visuwesh, emacs-devel

Stefan Kangas <stefankangas@gmail.com> writes:

> Philip Kaludercic <philipk@posteo.net>:
>
>> Alternatively (length (match-buffers '(derived-mode . dictionary-mode)))
>
> Nice golfing, thanks.  I installed that.

Though one should note that it does cons unnecessarily.  It probably
doesn't matter that much, due to the scope of the problem, but perhaps
it would be a good idea to add an optional COUNT argument to
`match-buffer', like the one that was added to `directory-files'.



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

end of thread, other threads:[~2023-08-19 15:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <169185199333.11628.2162615922937919004@vcs2.savannah.gnu.org>
     [not found] ` <20230812145313.C853CC038C2@vcs2.savannah.gnu.org>
2023-08-16 12:55   ` master 5892b4db8de 2/3: Convert dictionary-mode to define-derived-mode Visuwesh
2023-08-16 19:45     ` Stefan Kangas
2023-08-16 22:33     ` Philip Kaludercic
2023-08-19 11:08       ` Stefan Kangas
2023-08-19 15:46         ` Philip Kaludercic
2023-08-17  9:15     ` Basil L. Contovounesios

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.