unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Akib Azmain Turja <akib@disroot.org>
To: Philip Kaludercic <philipk@posteo.net>
Cc: Emacs Developer List <emacs-devel@gnu.org>
Subject: Re: [NonGNU ELPA] New package: Denote-Refs
Date: Tue, 20 Dec 2022 00:00:52 +0600	[thread overview]
Message-ID: <87a63jp92j.fsf@disroot.org> (raw)
In-Reply-To: <87ili75o0p.fsf@posteo.net> (Philip Kaludercic's message of "Mon,  19 Dec 2022 16:58:14 +0000")

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

Philip Kaludercic <philipk@posteo.net> writes:

> Akib Azmain Turja <akib@disroot.org> writes:
>
>> Denote-Refs shows links and backlinks inline in a Denote note buffer,
>> just below the front matter of the note.
>>
>> Here is the patch:
>>
>> From f4145634df9eb45df7d526871c55326bfafb3785 Mon Sep 17 00:00:00 2001
>> From: Akib Azmain Turja <akib@disroot.org>
>> Date: Mon, 19 Dec 2022 22:22:46 +0600
>> Subject: [PATCH] * elpa-packages (denote-refs): New package.
>>
>> ---
>>  elpa-packages | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/elpa-packages b/elpa-packages
>> index 9dde563..1d26a5a 100644
>> --- a/elpa-packages
>> +++ b/elpa-packages
>> @@ -108,6 +108,8 @@
>>    :ignored-files ("LICENSE" "test" "Cask" "Makefile")
>>    :news "CHANGELOG.md")
>>
>> + (denote-refs           :url "https://codeberg.org/akib/emacs-denote-refs")
>> +
>>   (devhelp               :url "https://codeberg.org/akib/emacs-devhelp")
>>
>>   (diff-ansi		:url "https://codeberg.org/ideasman42/emacs-diff-ansi"
>> --
>> 2.37.1
>
> Here are a few comments:
>
> diff -u /tmp/denote-refs.el.1 /tmp/denote-refs.el
> --- /tmp/denote-refs.el.1	2022-12-19 19:38:55.000000000 +0100
> +++ /tmp/denote-refs.el	2022-12-19 17:57:48.712068577 +0100

Wow, nanosecond precision.  :O

> @@ -5,8 +5,8 @@
>  ;; Author: Akib Azmain Turja <akib@disroot.org>
>  ;; Created: 2022-12-18
>  ;; Version: 0.1
> -;; Package-Requires: ((emacs "28.1"))
> -;; Keywords: hypermedia outlines files
> +;; Package-Requires: ((emacs "28.1") (denote "1.2.0"))
> +;; Keywords: hypermedia, outlines, files
>  ;; URL: https://codeberg.org/akib/emacs-denote-refs

Whoops, I forgot that.  :(
Done.

>
>  ;; This file is not part of GNU Emacs.
> @@ -36,12 +36,11 @@
>  (require 'denote)
>  (require 'subr-x)
>
> -(defgroup denote-refs nil
> +(defgroup denote-refs '()

Why?

>    "Show links and backlinks in Denote notes."
>    :group 'denote
> -  :group 'hypermedia
> -  :group 'outlines
> -  :group 'files
> +  ;; You don't need to add multiple groups, we only need it to appear
> +  ;; once in the customize hierarchy
>    :link '(url-link "https://codeberg.org/akib/emacs-denote-refs")
>    :prefix "denote-refs-")
>

Done.

> @@ -62,7 +61,8 @@
>
>  Available sections are `links' and `backlinks', which shows the list
>  of linked file and the list of backlinks respectively."
> -  :type '(set (const :tag "Links" links)
> +  :type '(set :greedy t
> +	      (const :tag "Links" links)
>                (const :tag "Backlinks" backlinks)))

What does ':greedy t' mean?

And anyway, I'm going to change that with 'repeat', since
'(links backlinks)', '(backlinks links)' and '(links backlinks links)'
all have meanings now.

New type: '(repeat (choice (const :tag "Links" links)
                           (const :tag "Backlinks" backlinks)))

Again the space-tab problem.  Added .dir-locals.el.

>
>  (defvar denote-refs--links 'not-ready
> @@ -83,65 +83,67 @@
>  (defun denote-refs--render (section)
>    "Render SECTION."
>    (let ((refs (pcase section
> -                ('links denote-refs--links)
> -                ('backlinks denote-refs--backlinks))))
> -    (pcase major-mode
> -      ;; There's no comment syntax in `text-mode', so just follow
> -      ;; `org-mode'.
> -      ((or 'org-mode 'text-mode)
> -       ;; Insert references count.
> -       (insert (if (eq refs 'not-ready)
> -                   (format "# ... %s\n" (if (eq section 'links)
> -                                            "links"
> -                                          "backlinks"))
> -                 (format "# %i %s%s\n" (length refs)
> -                         (if (eq section 'links)
> -                             "link"
> -                           "backlink")
> -                         (pcase (length refs)
> -                           (0 "")
> -                           (1 ":")
> -                           (_ "s:")))))
> -       ;; Insert reference list.
> -       (when (listp refs)
> -         (dolist (ref refs)
> -           (insert "#   ")
> -           (insert-button (car ref)
> -                          'help-echo (cdr ref)
> -                          'face 'denote-faces-link
> -                          'action (lambda (_)
> -                                    (funcall denote-link-button-action
> -                                             (cdr ref))))
> -           (insert ?\n))))
> -      ('markdown-mode
> -       ;; Insert references count.
> -       (insert (if (eq refs 'not-ready)
> -                   (format "<!-- ... %s -->\n" (if (eq section 'links)
> -                                                   "links"
> -                                                 "backlinks"))
> -                 (format "<!-- %i %s%s\n" (length refs)
> -                         (if (eq section 'links)
> -                             "link"
> -                           "backlink")
> -                         (pcase (length refs)
> -                           (0 " -->")
> -                           (1 ":")
> -                           (_ "s:")))))
> -       ;; Insert reference list.
> -       (when (listp refs)
> -         (while refs
> -           (let ((ref (pop refs)))
> -             (insert "  ")
> -             (insert-button
> -              (car ref)
> -              'help-echo (cdr ref)
> -              'face 'denote-faces-link
> -              'action (lambda (_)
> -                        (funcall denote-link-button-action
> -                                 (cdr ref))))
> -             (unless refs
> -               (insert " -->"))
> -             (insert ?\n))))))))
> +		('links denote-refs--links)
> +		('backlinks denote-refs--backlinks))))
> +    (cond
> +     ;; There's no comment syntax in `text-mode', so just follow
> +     ;; `org-mode'.
> +     ((derived-mode-p 'org-mode 'text-mode)
> +      ;; Insert references count.
> +      (insert (if (eq refs 'not-ready)
> +		  (format "# ... %s\n" (if (eq section 'links)
> +					   "links"
> +					 "backlinks"))
> +		(format "# %i %s%s\n" (length refs)
> +			(if (eq section 'links)
> +			    "link"
> +			  "backlink")
> +			(pcase (length refs)
> +			  (0 "")
> +			  (1 ":")
> +			  (_ "s:")))))
> +      ;; Insert reference list.
> +      (when (listp refs)
> +	(dolist (ref refs)
> +	  (insert "#   ")
> +	  (insert-button (car ref)
> +			 'help-echo (cdr ref)
> +			 'face 'denote-faces-link
> +			 'action (lambda (_)
> +				   (funcall denote-link-button-action
> +					    (cdr ref))))
> +	  ;; Could (newline) work here?
> +	  (insert ?\n))))
> +     ((derived-mode-p 'markdown-mode)
> +      ;; Insert references count.
> +      (insert (if (eq refs 'not-ready)
> +		  (format "<!-- ... %s -->\n" (if (eq section 'links)
> +						  "links"
> +						"backlinks"))
> +		(format "<!-- %i %s%s\n" (length refs)
> +			(if (eq section 'links)
> +			    "link"
> +			  "backlink")
> +			(pcase (length refs)
> +			  (0 " -->")
> +			  (1 ":")
> +			  (_ "s:")))))
> +      ;; Insert reference list.
> +      (when (listp refs)
> +	(while refs
> +	  (let ((ref (pop refs)))
> +	    (insert "  ")
> +	    (insert-button
> +	     (car ref)
> +	     'help-echo (cdr ref)
> +	     'face 'denote-faces-link
> +	     ;; This way we avoid creating a closure that ignores an
> +	     ;; argument.
> +	     'action #'denote-link-button-action
> +	     'button-data (cdr ref))
> +	    (unless refs
> +	      (insert " -->"))
> +	    (insert ?\n))))))))

+1.  Done.

>
>  (defun denote-refs--goto-end-of-front-matter ()
>    "Go to the end of front matter of the note."
> @@ -159,15 +161,14 @@
>      (save-excursion
>        (denote-refs--goto-end-of-front-matter)
>        (when (get-text-property (point) 'denote-refs--sections)
> -        (let ((end (or (next-single-property-change
> -                        (point) 'denote-refs--sections)
> -                       (point-max))))
> -          (when (< end (point-max))
> -            (setq end (1+ end)))
> -          (let ((mod-flag (buffer-modified-p))
> -                (inhibit-read-only t))
> -            (delete-region (point) end)
> -            (restore-buffer-modified-p mod-flag)))))))
> +	(let ((end (or (next-single-property-change
> +			(point) 'denote-refs--sections)
> +		       (point-max)))
> +	      (inhibit-read-only t))
> +	  (when (< end (point-max))
> +	    (setq end (1+ end)))
> +	  (with-silent-modifications
> +	    (delete-region (point) end)))))))
>
>  (defun denote-refs--show ()
>    "Show references."
> @@ -177,19 +178,18 @@
>      (denote-refs--remove)
>      (save-excursion
>        (denote-refs--goto-end-of-front-matter)
> -      (let ((begin (point))
> -            (mod-flag (buffer-modified-p))
> -            (inhibit-read-only t))
> -        (dolist (section denote-refs-sections)
> -          (pcase-exhaustive section
> -            ('links
> -             (denote-refs--render 'links))
> -            ('backlinks
> -             (denote-refs--render 'backlinks))))
> -        (put-text-property begin (point) 'read-only t)
> -        (put-text-property begin (point) 'denote-refs--sections t)
> -        (insert ?\n)
> -        (restore-buffer-modified-p mod-flag)))))
> +      (with-silent-modifications
> +	(let ((begin (point))
> +	      (inhibit-read-only t))
> +	  (dolist (section denote-refs-sections)
> +	    (pcase-exhaustive section
> +	      ('links
> +	       (denote-refs--render 'links))
> +	      ('backlinks
> +	       (denote-refs--render 'backlinks))))
> +	  (put-text-property begin (point) 'read-only t)
> +	  (put-text-property begin (point) 'denote-refs--sections t)
> +	  (insert ?\n))))))

+1.  Done.  Also got rid of the undo problem.  :)

>
>  (defun denote-refs--make-path-relative (path)
>    "Return a cons of relative and absolute version of PATH.
> @@ -203,22 +203,22 @@
>      (pcase-exhaustive section
>        ('links
>         (setq denote-refs--links
> -             (when (and (buffer-file-name)
> -                        (file-exists-p (buffer-file-name)))
> -               (mapcar #'denote-refs--make-path-relative
> -                       (denote-link--expand-identifiers
> -                        (denote--link-in-context-regexp
> -                         (denote-filetype-heuristics
> -                          (buffer-file-name))))))))
> +	     (and (buffer-file-name)
> +		  (file-exists-p (buffer-file-name))
> +		  (mapcar #'denote-refs--make-path-relative
> +			  (denote-link--expand-identifiers
> +			   (denote--link-in-context-regexp
> +			    (denote-filetype-heuristics
> +			     (buffer-file-name))))))))
>        ('backlinks
>         (setq denote-refs--backlinks
> -             (when (and (buffer-file-name)
> -                        (file-exists-p (buffer-file-name)))
> -               (mapcar #'denote-refs--make-path-relative
> -                       (delete (buffer-file-name)
> -                               (denote--retrieve-files-in-xrefs
> -                                (denote-retrieve-filename-identifier
> -                                 (buffer-file-name)))))))))))
> +	     (and (buffer-file-name)
> +		  (file-exists-p (buffer-file-name))
> +		  (mapcar #'denote-refs--make-path-relative
> +			  (delete (buffer-file-name)
> +				  (denote--retrieve-files-in-xrefs
> +				   (denote-retrieve-filename-identifier
> +				    (buffer-file-name)))))))))))
>

OK.  Done.

>  (defun denote-refs-update ()
>    "Update Denote references shown."
>
> Diff finished.  Mon Dec 19 17:57:57 2022

Thanks for the information.  I guess you live somewhere at UTC+1, based
on the email timestamp and diff timestamp.

>

FYI, you missed the missing ;;;###autoload.  I just added it.

--
Akib Azmain Turja, GPG key: 70018CE5819F17A3BBA666AFE74F0EFA922AE7F5
Fediverse: akib@hostux.social
Codeberg: akib
emailselfdefense.fsf.org | "Nothing can be secure without encryption."

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

  reply	other threads:[~2022-12-19 18:00 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-19 16:31 [NonGNU ELPA] New package: Denote-Refs Akib Azmain Turja
2022-12-19 16:58 ` Philip Kaludercic
2022-12-19 18:00   ` Akib Azmain Turja [this message]
2022-12-19 19:19     ` Philip Kaludercic
2022-12-19 20:20       ` [External] : " Drew Adams
2022-12-19 21:08         ` Philip Kaludercic
2022-12-19 21:51           ` Drew Adams
2022-12-20 16:48             ` Philip Kaludercic
2022-12-20 17:39               ` Drew Adams
2022-12-21  0:05                 ` Philip Kaludercic
2022-12-21  5:22                   ` Drew Adams
2022-12-21  9:07                     ` Philip Kaludercic
2022-12-21 15:50                       ` Drew Adams
2022-12-20 15:09       ` Akib Azmain Turja
2022-12-20 16:55         ` Philip Kaludercic
2022-12-20 20:17           ` Akib Azmain Turja
2022-12-20 22:02             ` Stefan Monnier
2022-12-21 16:03               ` Akib Azmain Turja

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a63jp92j.fsf@disroot.org \
    --to=akib@disroot.org \
    --cc=emacs-devel@gnu.org \
    --cc=philipk@posteo.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).