From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: FW: [RFC] Link-type for attachments, more attach options Date: Sun, 04 Nov 2018 23:37:19 +0100 Message-ID: <87muqo8o68.fsf@nicolasgoaziou.fr> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:41879) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJR1a-0004eS-IF for emacs-orgmode@gnu.org; Sun, 04 Nov 2018 17:37:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gJR1T-0004RN-1D for emacs-orgmode@gnu.org; Sun, 04 Nov 2018 17:37:38 -0500 Received: from relay8-d.mail.gandi.net ([217.70.183.201]:39163) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gJR1H-0003O0-Tu for emacs-orgmode@gnu.org; Sun, 04 Nov 2018 17:37:27 -0500 In-Reply-To: ("Gustav =?utf-8?Q?Wikstr=C3=B6m=22's?= message of "Sun, 21 Oct 2018 07:53:38 +0000") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Gustav =?utf-8?Q?Wikstr=C3=B6m?= Cc: "emacs-orgmode@gnu.org" Hello, Gustav Wikstr=C3=B6m writes: > I=E2=80=99ve attached a patch with some suggested additions to org-attach. > Patch comments below. Please review. Thank you. Some comments follow. > * Add new linktype "attached" for attachments This seem a bit long. Why not "att" links? > * Add further options for ATTACH_DIR > > When working with ATTACH_DIR there are now a couple of new options availa= ble: > - org-attach-dir-inherit-by-default What is the difference between this and `org-attach-allow-inheritance'? > - org-attach-dir-create-if-not-exist What is the use-case for this one? It doesn't seem terribly useful at first glance. > - org-attach-dir-relative I'm not sure to understand this one. > > +This list shows the full set of built-in external link types: > +| http | web | > +| https | secure web | > +| doi | DOI for electronic resources | > +| file | file-links | > +| file+sys | file-links forced to open via OS | > +| file+emacs | file-links forced to open via emacs | > +| attached | links to attachments for nodes | > +| docview | doc-view mode | > +| id | Link to heading by id | > +| news | Usenet link | > +| mailto | mail link | > +| mhe | MH-E folder link | > +| rmail | Rmail link | > +| gnus | Gnus link | > +| bbdb | BBDB link | > +| irc | IRC link | > +| info | Info link | > +| shell | shell command | > +| elisp | interactive elisp command link | > + > +The following list shows examples for each link type. > + > +| =3Dhttp://www.astro.uva.nl/=3Ddominik=3D | on the web = | > +| =3Ddoi:10.1000/182=3D | DOI for an electronic = resource | > +| =3Dfile:/home/dominik/images/jupiter.jpg=3D | file, absolute path = | > +| =3D/home/dominik/images/jupiter.jpg=3D | same as above = | > +| =3Dfile:papers/last.pdf=3D | file, relative path = | > +| =3D./papers/last.pdf=3D | same as above = | > +| =3Dfile:/ssh:me@some.where:papers/last.pdf=3D | file, path on remote m= achine | > +| =3D/ssh:me@some.where:papers/last.pdf=3D | same as above = | > +| =3Dfile:sometextfile::NNN=3D | file, jump to line num= ber | > +| =3Dfile:projects.org=3D | another Org file = | > +| =3Dfile:projects.org::some words=3D | text search in Org fil= e[fn:28] | > +| =3Dfile:projects.org::*task title=3D | heading search in Org = file | > +| =3Dfile+sys:/path/to/file=3D | open via OS, like doub= le-click | > +| =3Dfile+emacs:/path/to/file=3D | force opening by Emacs= | > +| =3Dattached:projects.org=3D | file in folder attache= d to headline | > +| =3Dattached:projects.org::some words=3D | text search in attache= d file | > +| =3Ddocview:papers/last.pdf::NNN=3D | open in doc-view mode = at page | > +| =3Did:B7423F4D-2E8A-471B-8810-C40F074717E9=3D | link to heading by ID = | > +| =3Dnews:comp.emacs=3D | Usenet link = | > +| =3Dmailto:adent@galaxy.net=3D | mail link = | > +| =3Dmhe:folder=3D | MH-E folder link = | > +| =3Dmhe:folder#id=3D | MH-E message link = | > +| =3Drmail:folder=3D | Rmail folder link = | > +| =3Drmail:folder#id=3D | Rmail message link = | > +| =3Dgnus:group=3D | Gnus group link = | > +| =3Dgnus:group#id=3D | Gnus article link = | > +| =3Dbbdb:R.*Stallman=3D | BBDB link (with regexp= ) | > +| =3Dirc:/irc.com/#emacs/bob=3D | IRC link = | > +| =3Dinfo:org#External links=3D | Info node link = | > +| =3Dshell:ls *.org=3D | shell command = | > +| =3Delisp:org-agenda=3D | interactive Elisp comm= and | > +| =3Delisp:(find-file "Elisp.org")=3D | Elisp form to evaluate= | I'm not sure to like the change above. It introduces a lot of redundancy. > Here is the syntax of the different ways to attach a search to a file > link, together with explanations for each: >=20=20 > #+begin_example > -[[file:~/code/main.c::255]] > -[[file:~/xx.org::My Target]] > -[[file:~/xx.org::*My Target]] > -[[file:~/xx.org::#my-custom-id]] > -[[file:~/xx.org::/regexp/]] > + [[file:~/code/main.c::255]] > + [[file:~/xx.org::My Target]] > + [[file:~/xx.org::*My Target]] > + [[file:~/xx.org::#my-custom-id]] > + [[file:~/xx.org::/regexp/]] > + [[attached:~/code/main.c::255]] > #+end_example Please discard this change. > +Another method is /attachments/, which are files located in a > +directory belonging to an outline node. Org uses directories either > +named by the unique ID of each entry, or by the =3DATTACH_DIR=3D propert= y. > +ID-based directories are by default located in the ~data~ directory ... =3Ddata/=3D directory, which ... > +(defcustom org-attach-dir-inherit-by-default nil > + "Defines whether ATTACH_DIR-directories should be inherited by > + subheadings by default when created. Defaults to not being > + inherited." > + :group 'org-attach > + :type 'boolean) First line in a docstring must be a full sentence. Indentation is wrong in the subsequent lines. Also, the `defcustom' is missing keywords, e.g., :package-version and :safe. > +(defcustom org-attach-dir-create-if-not-exists t > + "Choose whether ATTACH_DIR-directories should be created if > +they do not exist since before. Default is to create them." > + :group 'org-attach > + :type 'boolean) > + > +(defcustom org-attach-dir-relative nil > + "Choose whether ATTACH_DIR-directories should be added as > +relative links or not. Defaults to not relative." > + :group 'org-attach > + :type 'boolean) Ditto. > (defcustom org-attach-commit t > "If non-nil commit attachments with git. > This is only done if the Org file is in a git repository." > @@ -280,20 +299,26 @@ Throw an error if we cannot root the directory." > "Set the ATTACH_DIR node property and ask to move files there. > The property defines the directory that is used for attachments > of the entry. When called with `\\[universal-argument]', reset \ > -the directory to > -the default ID based one." > +the directory to the default ID based one. Creates relative links You need to use two spaces to separate sentences. > + (let ((old (org-attach-dir nil)) > + (new > + (progn > + (if arg (org-entry-delete nil "ATTACH_DIR") > + (let* ((attach-dir (read-directory-name > + "Attachment directory: " > + (org-entry-get nil > + "ATTACH_DIR"))) > + (current-dir (file-name-directory (or load-file-name > + buffer-file-name))) Why `load-file-name'? Why not using `default-directory'? > +(defun org-attach-open-link (link &optional in-emacs) > + "LINK is expanded with the attached directory and opened the same > +way as file-links are." You need to expound the arguments in the docstring. > + (file-types-re (format "[][]\\[\\(?:file\\|attached\\|[./~]%s\\)" > (if (not link-abbrevs) "" > (format "\\|\\(?:%s:\\)" > (regexp-opt link-abbrevs)))))) Why is it needed? "attached" link type is already registered, so you don't need to also hard-code it here. > + (when (and (or (equal "file" (org-element-property :type link)) > + (equal "attached" (org-element-property :type = link))) Ditto. > + (let ((file (if (equal "attached" (org-element-property :type link= )) > + (require 'org-attach) > + (org-attach-expand > + (org-link-unescape > + (org-element-property :path link))) > + (expand-file-name > + (org-link-unescape > + (org-element-property :path link)))))) Ditto. Regards, --=20 Nicolas Goaziou