emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* How to display overlay or propertize text on file: link type about the file?
@ 2020-02-20 15:58 stardiviner
  2020-02-22 21:52 ` John Kitchin
  0 siblings, 1 reply; 4+ messages in thread
From: stardiviner @ 2020-02-20 15:58 UTC (permalink / raw)
  To: Org Mode

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

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

* Re: How to display overlay or propertize text on file: link type about the file?
  2020-02-20 15:58 How to display overlay or propertize text on file: link type about the file? stardiviner
@ 2020-02-22 21:52 ` John Kitchin
  2020-02-23  4:54   ` stardiviner
  0 siblings, 1 reply; 4+ messages in thread
From: John Kitchin @ 2020-02-22 21:52 UTC (permalink / raw)
  To: numbchild; +Cc: Org Mode

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

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.

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
>  "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-----


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

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

* Re: How to display overlay or propertize text on file: link type about the file?
  2020-02-22 21:52 ` John Kitchin
@ 2020-02-23  4:54   ` stardiviner
  2020-02-23 13:46     ` John Kitchin
  0 siblings, 1 reply; 4+ messages in thread
From: stardiviner @ 2020-02-23  4:54 UTC (permalink / raw)
  To: John Kitchin; +Cc: Org Mode

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

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

* Re: How to display overlay or propertize text on file: link type about the file?
  2020-02-23  4:54   ` stardiviner
@ 2020-02-23 13:46     ` John Kitchin
  0 siblings, 0 replies; 4+ messages in thread
From: John Kitchin @ 2020-02-23 13:46 UTC (permalink / raw)
  To: stardiviner; +Cc: Org Mode

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

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 <numbchild@gmail.com> wrote:

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

[-- Attachment #2: Type: text/html, Size: 6121 bytes --]

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

end of thread, other threads:[~2020-02-23 13:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-20 15:58 How to display overlay or propertize text on file: link type about the file? stardiviner
2020-02-22 21:52 ` John Kitchin
2020-02-23  4:54   ` stardiviner
2020-02-23 13:46     ` John Kitchin

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

	https://git.savannah.gnu.org/cgit/emacs/org-mode.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).