From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.devel Subject: Re: [NonGNU ELPA] New package: Denote-Refs Date: Mon, 19 Dec 2022 16:58:14 +0000 Message-ID: <87ili75o0p.fsf@posteo.net> References: <87a63jl5i2.fsf@disroot.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12209"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Emacs Developer List To: Akib Azmain Turja Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Dec 19 17:58:48 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p7JTU-0002vx-3s for ged-emacs-devel@m.gmane-mx.org; Mon, 19 Dec 2022 17:58:48 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p7JTD-0003Z7-MP; Mon, 19 Dec 2022 11:58:31 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p7JSy-0003XS-OM for emacs-devel@gnu.org; Mon, 19 Dec 2022 11:58:30 -0500 Original-Received: from mout02.posteo.de ([185.67.36.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p7JSv-0005fd-T5 for emacs-devel@gnu.org; Mon, 19 Dec 2022 11:58:16 -0500 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id DBE0A240104 for ; Mon, 19 Dec 2022 17:58:11 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1671469091; bh=5Xyj49xQdoRPoJ8/BeKEAF3ZFmRv0RFRnK7IYvvmLWg=; h=From:To:Cc:Subject:Date:From; b=PQCLngfTbw/oluxJjNgaYcqbADEYfVFvmiTdC1NB4F+ga3Gj35iPbNWUwsvu+hw0a 9mjYNhQOf8YoxXO9CvACL8gPkO5Uc3N3bLjkg9+CtgvF8+81dSyKsLqwNc2XnHh3rL RDenoHDn5KfM015fRG/ejYwL6nJe9qf7VD3BaTK5l8/7BkiQivGdF+WsFIpzg68oNI SRmOVe5iYX9RiM1llSz9qU+PMuq06GvmyzZ1fAQQnLge5S8wF+l6NKdRfgmYBLAyJA 5vuNE+sVKIlvabg7WDoTyhxqRrhJV9uCWnC+dfLx5kpnXK15QkimUZyKgjlVypuo0g DgAcmWMgfNfZg== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4NbQrM3KbPz6tmG; Mon, 19 Dec 2022 17:58:11 +0100 (CET) In-Reply-To: <87a63jl5i2.fsf@disroot.org> (Akib Azmain Turja's message of "Mon, 19 Dec 2022 22:31:33 +0600") Received-SPF: pass client-ip=185.67.36.66; envelope-from=philipk@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:301659 Archived-At: --=-=-= Content-Type: text/plain Akib Azmain Turja 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 > 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: --=-=-= Content-Type: text/plain Content-Disposition: inline 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 @@ -5,8 +5,8 @@ ;; Author: Akib Azmain Turja ;; 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 ;; This file is not part of GNU Emacs. @@ -36,12 +36,11 @@ (require 'denote) (require 'subr-x) -(defgroup denote-refs nil +(defgroup denote-refs '() "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-") @@ -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))) (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 "\n" (if (eq section 'links) - "links" - "backlinks")) - (format "") - (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 "\n" (if (eq section 'links) + "links" + "backlinks")) + (format "") + (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)))))))) (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)))))) (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))))))))))) (defun denote-refs-update () "Update Denote references shown." Diff finished. Mon Dec 19 17:57:57 2022 --=-=-=--