From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: Re: How to display overlay or propertize text on file: link type about the file? Date: Sun, 23 Feb 2020 08:46:54 -0500 Message-ID: References: <87v9o16yix.fsf@gmail.com> <8736b1c390.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000859820059f3e7d73" Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:43991) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j5rbB-0001G7-LR for emacs-orgmode@gnu.org; Sun, 23 Feb 2020 08:47:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j5rb9-0006Vw-PW for emacs-orgmode@gnu.org; Sun, 23 Feb 2020 08:47:09 -0500 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]:35091) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j5rb9-0006Ve-HO for emacs-orgmode@gnu.org; Sun, 23 Feb 2020 08:47:07 -0500 Received: by mail-wm1-x335.google.com with SMTP id b17so6659311wmb.0 for ; Sun, 23 Feb 2020 05:47:07 -0800 (PST) In-Reply-To: <8736b1c390.fsf@gmail.com> 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-mx.org@gnu.org Sender: "Emacs-orgmode" To: stardiviner Cc: Org Mode --000000000000859820059f3e7d73 Content-Type: text/plain; charset="UTF-8" In that case: #+BEGIN_SRC emacs-lisp (defun file-description (start end path bracketp) (put-text-property start end 'display (shell-command-to-string (format "file %s" path)))) (org-link-set-parameters "file" :activate-func 'file-description) #+END_SRC With this, you have to have a way to insert links that isn't typing them in by hand; as soon as emacs recognizes the link, it changes the display which makes it hard to type. The shell command puts a long string, so you might replace that with something that has the output you wanted above. John ----------------------------------- Professor John Kitchin Doherty Hall A207F Department of Chemical Engineering Carnegie Mellon University Pittsburgh, PA 15213 412-268-7803 @johnkitchin http://kitchingroup.cheme.cmu.edu On Sat, Feb 22, 2020 at 11:55 PM stardiviner wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA256 > > > John Kitchin writes: > > > I think you are looking for the :activate-func property of a link. What > > you want is somewhat tricky though, how would you edit the link? > > > > There is an example at > > > https://kitchingroup.cheme.cmu.edu/blog/2016/11/04/New-link-features-in-org-9/#org069cbfa > > Thanks for your tips. Helpful!! > > > > > that might give you some ideas. You can use a 'display text property to > > change the appearance, but you need some way to remove this if you want > > to edit or see the original version. > > I usually edit link with =[C-c C-l]= to edit link URL and description, not > literally. > > > > > stardiviner writes: > > > >> -----BEGIN PGP SIGNED MESSAGE----- > >> Hash: SHA256 > >> > >> > >> I have a requirement, I want to display file: link's file type info on > the link. > >> > >> For example, an Org file: link > >> > >> #+begin_src org > >> [[file:~/Org/logo.png][logo]] > >> [[file:~/Org/document.pdf][document]] > >> [[file:~/Org/book.epub][book]] > >> #+end_src > >> > >> I want to display link as: > >> > >> #+begin_src org > >> logo (image: png) > >> document (document: pdf) > >> book (ebook: epub) > >> #+end_src > >> > >> I'm inspired by this code snippet: > >> > >> #+begin_src emacs-lisp > >> (org-link-set-parameters > >> "file+sys" > >> :complete 'org-file-complete-link > >> :face (lambda (path) (if (file-exists-p path) 'org-link 'org-warning))) > >> #+end_src > >> > >> Is it possible to display those info between parentheses with an > overlay or > >> propertied text? > >> > >> If someone have any idea or how to implement this, please help me. > Thanks in advanced. > >> > >> - -- > >> [ stardiviner ] > >> I try to make every word tell the meaning what I want to express. > >> > >> Blog: https://stardiviner.github.io/ > >> IRC(freenode): stardiviner, Matrix: stardiviner > >> GPG: F09F650D7D674819892591401B5DF1C95AE89AC3 > >> > >> -----BEGIN PGP SIGNATURE----- > >> > >> iQFIBAEBCAAyFiEE8J9lDX1nSBmJJZFAG13xyVromsMFAl5OrLYUHG51bWJjaGls > >> ZEBnbWFpbC5jb20ACgkQG13xyVromsPElQf/W71U1JQ9ZeFjCWCxICs0q87016Iq > >> 8FQ5Fr3lSmRb6NRLqzqAAbY6b14roxtixxmllvArJgd7bz280xTZs3NGgYMm/HMf > >> sZ+vtkpiHgJk31KXxAk/LT1OcgzYOrSv7g6c8Y3Gg8G5eSDmKGu+tMwqFzYtVmk2 > >> 6G0/wz9ezsdYAFLlNrX/FhcVaxCUSSdG08z0Ip/Op1I4iqh3Y86N7LalPVZWNa9H > >> eZSFsf3Z8NqfVnCmTvmyJon4x1SGvJ8Iaf4QUiE7huNeizJK2+CSIhjSu8yDBGr4 > >> 2oMPrkAm1XkJDLMQh0FLjIrIJUoTLzLonEYtlmg3thvFEMqFuF8ziYaGdw== > >> =sZhk > >> -----END PGP SIGNATURE----- > > > - -- > [ stardiviner ] > I try to make every word tell the meaning what I want to express. > > Blog: https://stardiviner.github.io/ > IRC(freenode): stardiviner, Matrix: stardiviner > GPG: F09F650D7D674819892591401B5DF1C95AE89AC3 > > -----BEGIN PGP SIGNATURE----- > > iQFIBAEBCAAyFiEE8J9lDX1nSBmJJZFAG13xyVromsMFAl5SBYsUHG51bWJjaGls > ZEBnbWFpbC5jb20ACgkQG13xyVromsOSOAgAmtN0JBgMB//D8EC7tQhrSwVX7spb > NLH2EQbdDmzOyf2y+gwrvzGBojQ7TBLmM/dzm+IfPNsbyY4IMlLBvyrJST7D0uDC > SXA8Ugi88qKkyS5H+Hw5jSNcOaPxwXLq5kxu3BXmtBpdNiIShL0qnTD4itNRHpG8 > v0NWFQwTcMI15OcsTKoGSG9PNw7qeJEt5vpYLL/oljAxMW0VsCnS061XjWda8w5u > U2KWYLCeVAh3kXtas5pywar50F+ELAoutpr3USqJDtFPtRkyVYAmEKBHknFJ2R4u > 8nTIchXoctS5JpINhwq4wfdmSRSjjcz1DYb9Y9LSMFjDbvzAKqcSk6eX4g== > =xhBz > -----END PGP SIGNATURE----- > > --000000000000859820059f3e7d73 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
In that case:

#+BEGIN_SRC emacs-lisp(defun file-description (start end path bracketp)
=C2=A0 (put-text-prop= erty start end 'display (shell-command-to-string
(format "= ;file %s" path))))

(org-link-set-parameters
=C2=A0"file= "
=C2=A0:activate-func 'file-description)
#+END_SRC

With this, you have to have a way to insert links that isn= 't typing them in by hand; as soon as emacs recognizes the link, it cha= nges the display which makes it hard to type.

The = shell command puts a long string, so you might replace that with something = that has the output you wanted above.
John

-----------------------------------<= br>Professor John Kitchin=C2=A0
Doherty Hall A207F
Department of Chem= ical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
4= 12-268-7803


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256


John Kitchin <jkitchin@andrew.cmu.edu> writes:

> I think you are looking for the :activate-func property of a link. Wha= t
> you want is somewhat tricky though, how would you edit the link?
>
> There is an example at
> https:= //kitchingroup.cheme.cmu.edu/blog/2016/11/04/New-link-features-in-org-9/#or= g069cbfa

Thanks for your tips. Helpful!!

>
> that might give you some ideas. You can use a 'display text proper= ty to
> change the appearance, but you need some way to remove this if you wan= t
> to edit or see the original version.

I usually edit link with =3D[C-c C-l]=3D to edit link URL and description, = not literally.

>
> stardiviner <numbchild@gmail.com> writes:
>
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA256
>>
>>
>> I have a requirement, I want to display file: link's file type= info on the link.
>>
>> For example, an Org file: link
>>
>> #+begin_src org
>> [[file:~/Org/logo.png][logo]]
>> [[file:~/Org/document.pdf][document]]
>> [[file:~/Org/book.epub][book]]
>> #+end_src
>>
>> I want to display link as:
>>
>> #+begin_src org
>> logo (image: png)
>> document (document: pdf)
>> book (ebook: epub)
>> #+end_src
>>
>> I'm inspired by this code snippet:
>>
>> #+begin_src emacs-lisp
>> (org-link-set-parameters
>>=C2=A0 "file+sys"
>>=C2=A0 :complete 'org-file-complete-link
>>=C2=A0 :face (lambda (path) (if (file-exists-p path) 'org-link = 'org-warning)))
>> #+end_src
>>
>> Is it possible to display those info between parentheses with an o= verlay or
>> propertied text?
>>
>> If someone have any idea or how to implement this, please help me.= Thanks in advanced.
>>
>> - --
>> [ stardiviner ]
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 I try to make every word tell the meani= ng what I want to express.
>>
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 Blog: https://stardiviner.github.i= o/
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 IRC(freenode): stardiviner, Matrix: sta= rdiviner
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 GPG: F09F650D7D674819892591401B5DF1C95A= E89AC3
>>
>> -----BEGIN PGP SIGNATURE-----
>>
>> iQFIBAEBCAAyFiEE8J9lDX1nSBmJJZFAG13xyVromsMFAl5OrLYUHG51bWJjaGls >> ZEBnbWFpbC5jb20ACgkQG13xyVromsPElQf/W71U1JQ9ZeFjCWCxICs0q87016Iq >> 8FQ5Fr3lSmRb6NRLqzqAAbY6b14roxtixxmllvArJgd7bz280xTZs3NGgYMm/HMf >> sZ+vtkpiHgJk31KXxAk/LT1OcgzYOrSv7g6c8Y3Gg8G5eSDmKGu+tMwqFzYtVmk2 >> 6G0/wz9ezsdYAFLlNrX/FhcVaxCUSSdG08z0Ip/Op1I4iqh3Y86N7LalPVZWNa9H >> eZSFsf3Z8NqfVnCmTvmyJon4x1SGvJ8Iaf4QUiE7huNeizJK2+CSIhjSu8yDBGr4 >> 2oMPrkAm1XkJDLMQh0FLjIrIJUoTLzLonEYtlmg3thvFEMqFuF8ziYaGdw=3D=3D >> =3DsZhk
>> -----END PGP SIGNATURE-----


- --
[ stardiviner ]
=C2=A0 =C2=A0 =C2=A0 =C2=A0I try to make every word tell the meaning what I= want to express.

=C2=A0 =C2=A0 =C2=A0 =C2=A0Blog: https://stardiviner.github.io/ =C2=A0 =C2=A0 =C2=A0 =C2=A0IRC(freenode): stardiviner, Matrix: stardiviner<= br> =C2=A0 =C2=A0 =C2=A0 =C2=A0GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
-----BEGIN PGP SIGNATURE-----

iQFIBAEBCAAyFiEE8J9lDX1nSBmJJZFAG13xyVromsMFAl5SBYsUHG51bWJjaGls
ZEBnbWFpbC5jb20ACgkQG13xyVromsOSOAgAmtN0JBgMB//D8EC7tQhrSwVX7spb
NLH2EQbdDmzOyf2y+gwrvzGBojQ7TBLmM/dzm+IfPNsbyY4IMlLBvyrJST7D0uDC
SXA8Ugi88qKkyS5H+Hw5jSNcOaPxwXLq5kxu3BXmtBpdNiIShL0qnTD4itNRHpG8
v0NWFQwTcMI15OcsTKoGSG9PNw7qeJEt5vpYLL/oljAxMW0VsCnS061XjWda8w5u
U2KWYLCeVAh3kXtas5pywar50F+ELAoutpr3USqJDtFPtRkyVYAmEKBHknFJ2R4u
8nTIchXoctS5JpINhwq4wfdmSRSjjcz1DYb9Y9LSMFjDbvzAKqcSk6eX4g=3D=3D
=3DxhBz
-----END PGP SIGNATURE-----

--000000000000859820059f3e7d73--