unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [ELPA] New consult-denote package
@ 2024-05-08 11:33 Protesilaos Stavrou
  2024-05-08 17:19 ` Philip Kaludercic
  0 siblings, 1 reply; 6+ messages in thread
From: Protesilaos Stavrou @ 2024-05-08 11:33 UTC (permalink / raw)
  To: emacs-devel

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

Hello folks!

I plan to push the attached change to elpa.git. Any thoughts?

The goal of this package is to enhance the minibuffer prompts of
'denote' with some of the features provided by 'consult'.

Both Consult and Denote are on GNU ELPA.

All the best,
Protesilaos (or simply "Prot")

-- 
Protesilaos Stavrou
https://protesilaos.com

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-elpa-packages-consult-denote-Add-new-package.patch --]
[-- Type: text/x-diff, Size: 860 bytes --]

From c3097070c9a427764c05749daecc6c303b87ec72 Mon Sep 17 00:00:00 2001
Message-Id: <c3097070c9a427764c05749daecc6c303b87ec72.1715167446.git.info@protesilaos.com>
From: Protesilaos Stavrou <info@protesilaos.com>
Date: Wed, 8 May 2024 14:23:15 +0300
Subject: [PATCH] * elpa-packages (consult-denote): Add new package

---
 elpa-packages | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/elpa-packages b/elpa-packages
index de66d29..02babee 100644
--- a/elpa-packages
+++ b/elpa-packages
@@ -170,6 +170,8 @@
   :doc "README.org"
   :news "CHANGELOG.org"
   :ignored-files ("LICENSE"))
+ (consult-denote		:url "https://github.com/protesilaos/consult-denote"
+  :readme "README.md")
  (consult-hoogle	:url "https://codeberg.org/rahguzar/consult-hoogle"
   :ignored-files ("LICENSE"))
  (consult-recoll	:url "https://codeberg.org/jao/consult-recoll"
-- 
2.39.2


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

* Re: [ELPA] New consult-denote package
  2024-05-08 11:33 [ELPA] New consult-denote package Protesilaos Stavrou
@ 2024-05-08 17:19 ` Philip Kaludercic
  2024-05-09  4:00   ` Protesilaos Stavrou
  0 siblings, 1 reply; 6+ messages in thread
From: Philip Kaludercic @ 2024-05-08 17:19 UTC (permalink / raw)
  To: Protesilaos Stavrou; +Cc: emacs-devel

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

Protesilaos Stavrou <info@protesilaos.com> writes:

> Hello folks!
>
> I plan to push the attached change to elpa.git. Any thoughts?
>
> The goal of this package is to enhance the minibuffer prompts of
> 'denote' with some of the features provided by 'consult'.
>
> Both Consult and Denote are on GNU ELPA.
>
> All the best,
> Protesilaos (or simply "Prot")
>
> -- 
> Protesilaos Stavrou
> https://protesilaos.com
>
> From c3097070c9a427764c05749daecc6c303b87ec72 Mon Sep 17 00:00:00 2001
> Message-Id: <c3097070c9a427764c05749daecc6c303b87ec72.1715167446.git.info@protesilaos.com>
> From: Protesilaos Stavrou <info@protesilaos.com>
> Date: Wed, 8 May 2024 14:23:15 +0300
> Subject: [PATCH] * elpa-packages (consult-denote): Add new package
>
> ---
>  elpa-packages | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/elpa-packages b/elpa-packages
> index de66d29..02babee 100644
> --- a/elpa-packages
> +++ b/elpa-packages
> @@ -170,6 +170,8 @@
>    :doc "README.org"
>    :news "CHANGELOG.org"
>    :ignored-files ("LICENSE"))
> + (consult-denote		:url "https://github.com/protesilaos/consult-denote"
> +  :readme "README.md")
>   (consult-hoogle	:url "https://codeberg.org/rahguzar/consult-hoogle"
>    :ignored-files ("LICENSE"))
>   (consult-recoll	:url "https://codeberg.org/jao/consult-recoll"

Here are a few quick comments:


[-- Attachment #2: Type: text/plain, Size: 2481 bytes --]

diff --git a/consult-denote.el b/consult-denote.el
index 135838e..76895a8 100644
--- a/consult-denote.el
+++ b/consult-denote.el
@@ -90,7 +90,7 @@ aforementioned function."
     (let* ((default-directory (denote-directory))
            (common-parent-directory
             (let ((common-prefix (try-completion "" all-files)))
-              (if (> (length common-prefix) 0)
+              (if (length> common-prefix 0)
                   (file-name-directory common-prefix))))
            (cpd-length (length common-parent-directory))
            (prompt-prefix (or prompt-text "Select FILE"))
@@ -101,16 +101,16 @@ aforementioned function."
                            (setq all-files
                                  (delete common-parent-directory all-files))
                            t))
-           (substrings (mapcar (lambda (s) (substring s cpd-length)) all-files))
-           (_ (when included-cpd
-                (setq substrings (cons "./" substrings))))
+           (substrings (append
+			(if included-cpd '("./"))
+			(mapcar (lambda (s) (substring s cpd-length)) all-files)))
            (new-collection (denote--completion-table 'file substrings))
            ;; We populate the history ourselves because we process the input.
            (input
             (consult--read new-collection
                            :state (consult--file-preview)
                            :prompt prompt))
-           ;; FIXME 2024-05-08: Is there some elegant way to do this?
+           ;; FIXME 2024-05-08: Is there some elegant way to do this? what is "this"
            (filename (with-temp-buffer
                        (insert input)
                        (completion-in-region (point-min) (point-max) new-collection)
@@ -164,14 +164,13 @@ aforementioned function."
 
 (defun consult-denote--buffers ()
   "Return file names of Denote buffers."
-  (delq nil
-        (mapcar
-         (lambda (buffer)
-           (when-let ((file (buffer-file-name buffer))
-                      ((buffer-live-p buffer))
-                      ((denote-filename-is-note-p file)))
-             (buffer-name buffer)))
-         (buffer-list))))
+  (mapcan				;or use `match-buffers'
+   (lambda (buffer)
+     (and-let* ((file (buffer-file-name buffer))
+                ((buffer-live-p buffer))
+                ((denote-filename-is-note-p file)))
+       (list (buffer-name buffer))))
+   (buffer-list)))
 
 (defvar consult-denote--buffer-source
   `( :name "Denote buffers"

[-- Attachment #3: Type: text/plain, Size: 38 bytes --]



-- 
	Philip Kaludercic on peregrine

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

* Re: [ELPA] New consult-denote package
  2024-05-08 17:19 ` Philip Kaludercic
@ 2024-05-09  4:00   ` Protesilaos Stavrou
  2024-05-09  8:20     ` Philip Kaludercic
  0 siblings, 1 reply; 6+ messages in thread
From: Protesilaos Stavrou @ 2024-05-09  4:00 UTC (permalink / raw)
  To: Philip Kaludercic; +Cc: emacs-devel

Thank you Philip!

> From: Philip Kaludercic <philipk@posteo.net>
> Date: Wed,  8 May 2024 17:19:51 +0000

> [... 74 lines elided]

> -           ;; FIXME 2024-05-08: Is there some elegant way to do this?
> +           ;; FIXME 2024-05-08: Is there some elegant way to do this? what is "this"
>             (filename (with-temp-buffer
>                         (insert input)
>                         (completion-in-region (point-min) (point-max) new-collection)

> [... 22 lines elided]

The FIXME there is about the following use of the temp buffer to do a
completion-in-region in. Basically, I was looking for a function that
would complete a string against the list of candidates. What I have
there works, of course, but feels I am missing something.

-- 
Protesilaos Stavrou
https://protesilaos.com



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

* Re: [ELPA] New consult-denote package
  2024-05-09  4:00   ` Protesilaos Stavrou
@ 2024-05-09  8:20     ` Philip Kaludercic
  2024-05-09  9:38       ` Protesilaos Stavrou
  0 siblings, 1 reply; 6+ messages in thread
From: Philip Kaludercic @ 2024-05-09  8:20 UTC (permalink / raw)
  To: Protesilaos Stavrou; +Cc: emacs-devel

Protesilaos Stavrou <info@protesilaos.com> writes:

> Thank you Philip!
>
>> From: Philip Kaludercic <philipk@posteo.net>
>> Date: Wed,  8 May 2024 17:19:51 +0000
>
>> [... 74 lines elided]
>
>> -           ;; FIXME 2024-05-08: Is there some elegant way to do this?
>> +           ;; FIXME 2024-05-08: Is there some elegant way to do this? what is "this"
>>             (filename (with-temp-buffer
>>                         (insert input)
>>                         (completion-in-region (point-min) (point-max) new-collection)
>
>> [... 22 lines elided]
>
> The FIXME there is about the following use of the temp buffer to do a
> completion-in-region in. Basically, I was looking for a function that
> would complete a string against the list of candidates. What I have
> there works, of course, but feels I am missing something.

Isn't that the same as

  (try-completion input new-collection)

or am I missing something?

-- 
	Philip Kaludercic on peregrine



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

* Re: [ELPA] New consult-denote package
  2024-05-09  8:20     ` Philip Kaludercic
@ 2024-05-09  9:38       ` Protesilaos Stavrou
  2024-05-09 10:30         ` Visuwesh
  0 siblings, 1 reply; 6+ messages in thread
From: Protesilaos Stavrou @ 2024-05-09  9:38 UTC (permalink / raw)
  To: Philip Kaludercic; +Cc: emacs-devel

> From: Philip Kaludercic <philipk@posteo.net>
> Date: Thu,  9 May 2024 08:20:50 +0000

> [... 18 lines elided]

>> The FIXME there is about the following use of the temp buffer to do a
>> completion-in-region in. Basically, I was looking for a function that
>> would complete a string against the list of candidates. What I have
>> there works, of course, but feels I am missing something.
>
> Isn't that the same as
>
>   (try-completion input new-collection)
>
> or am I missing something?

The 'try-completion' does not seem to read the 'completion-styles'. It
works if the input matches the prefix of the candidate, but otherwise it
returns nil.

Trying it with this:

    (defun denote--completion-table (category candidates)
      "Pass appropriate metadata CATEGORY to completion CANDIDATES."
      (lambda (string pred action)
        (if (eq action 'metadata)
            `(metadata (category . ,category))
          (complete-with-action action candidates string pred))))

    (setq completion-styles '(basic substring)) ; I also have `orderless' in my setup

    ;; This returns nil
    (try-completion
     "magritte"
     (denote--completion-table
      'file
      '("20220220T122457--magritte-pipe__attachment_painting_philosophy.jpg"
        "20231129T125442--note-with-a-title__denote_test.txt")))

    ;; This returns the candidate
    (try-completion
     "2022"
     (denote--completion-table
      'file
      '("20220220T122457--magritte-pipe__attachment_painting_philosophy.jpg"
        "20231129T125442--note-with-a-title__denote_test.txt")))

-- 
Protesilaos Stavrou
https://protesilaos.com



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

* Re: [ELPA] New consult-denote package
  2024-05-09  9:38       ` Protesilaos Stavrou
@ 2024-05-09 10:30         ` Visuwesh
  0 siblings, 0 replies; 6+ messages in thread
From: Visuwesh @ 2024-05-09 10:30 UTC (permalink / raw)
  To: Protesilaos Stavrou; +Cc: Philip Kaludercic, emacs-devel

[வியாழன் மே 09, 2024] Protesilaos Stavrou wrote:

>> From: Philip Kaludercic <philipk@posteo.net>
>> Date: Thu,  9 May 2024 08:20:50 +0000
>
>> [... 18 lines elided]
>
>>> The FIXME there is about the following use of the temp buffer to do a
>>> completion-in-region in. Basically, I was looking for a function that
>>> would complete a string against the list of candidates. What I have
>>> there works, of course, but feels I am missing something.
>>
>> Isn't that the same as
>>
>>   (try-completion input new-collection)
>>
>> or am I missing something?
>
> The 'try-completion' does not seem to read the 'completion-styles'. It
> works if the input matches the prefix of the candidate, but otherwise it
> returns nil.
>

What about completion-all-completions?

> [...]



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

end of thread, other threads:[~2024-05-09 10:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-08 11:33 [ELPA] New consult-denote package Protesilaos Stavrou
2024-05-08 17:19 ` Philip Kaludercic
2024-05-09  4:00   ` Protesilaos Stavrou
2024-05-09  8:20     ` Philip Kaludercic
2024-05-09  9:38       ` Protesilaos Stavrou
2024-05-09 10:30         ` Visuwesh

Code repositories for project(s) associated with this public inbox

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

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