emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Adding text properties to all Org mode links
@ 2013-07-13 13:40 Suvayu Ali
  2013-07-14  3:01 ` Nick Dokos
  0 siblings, 1 reply; 8+ messages in thread
From: Suvayu Ali @ 2013-07-13 13:40 UTC (permalink / raw)
  To: Emacs Org mode

Hi,

How do I add text properties to org elements?  In my particular case, I
want to echo tooltips when I move my cursor over an org link (or other
org elements for that matter).  To do this, I need to add the properties
point-left and point-entered to all org-links.  How do I do that?

Thanks for any ideas.

-- 
Suvayu

Open source is the future. It sets us free.

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

* Re: Adding text properties to all Org mode links
  2013-07-13 13:40 Adding text properties to all Org mode links Suvayu Ali
@ 2013-07-14  3:01 ` Nick Dokos
  2013-07-14  6:41   ` Suvayu Ali
  0 siblings, 1 reply; 8+ messages in thread
From: Nick Dokos @ 2013-07-14  3:01 UTC (permalink / raw)
  To: emacs-orgmode

Suvayu Ali <fatkasuvayu+linux@gmail.com> writes:

> Hi,
>
> How do I add text properties to org elements?  In my particular case, I
> want to echo tooltips when I move my cursor over an org link (or other
> org elements for that matter).  To do this, I need to add the properties
> point-left and point-entered to all org-links.  How do I do that?
>
> Thanks for any ideas.

Not sure if this is the best method:

o go to (point-min)
o loop
     (goto-char (cdr (org-element-link-successor (point-max))))
     (org-element-link-parser) and extract :begin and :end values from
     the returned list

Untested (mostly) - termination, error handling (and who knows what
else) left to the interested reader...
-- 
Nick

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

* Re: Adding text properties to all Org mode links
  2013-07-14  3:01 ` Nick Dokos
@ 2013-07-14  6:41   ` Suvayu Ali
  2013-09-09 23:15     ` Suvayu Ali
  0 siblings, 1 reply; 8+ messages in thread
From: Suvayu Ali @ 2013-07-14  6:41 UTC (permalink / raw)
  To: emacs-orgmode

Hi Nick,

On Sat, Jul 13, 2013 at 11:01:08PM -0400, Nick Dokos wrote:
> Suvayu Ali <fatkasuvayu+linux@gmail.com> writes:
> 
> > Hi,
> >
> > How do I add text properties to org elements?  In my particular case, I
> > want to echo tooltips when I move my cursor over an org link (or other
> > org elements for that matter).  To do this, I need to add the properties
> > point-left and point-entered to all org-links.  How do I do that?
> >
> > Thanks for any ideas.
> 
> Not sure if this is the best method:
> 
> o go to (point-min)
> o loop
>      (goto-char (cdr (org-element-link-successor (point-max))))
>      (org-element-link-parser) and extract :begin and :end values from
>      the returned list
> 
> Untested (mostly) - termination, error handling (and who knows what
> else) left to the interested reader...

I was afraid of this.  I think the safest way of not screwing up the
parsing and error handling would be to implement it as a patch to
org-activate-*-links in org.el.

I guess I should give some background info.  Lately (>1yr), I have been
using Emacs exclusively from the terminal.  In a gui, hovering the mouse
over a link shows you the target as a tooltip.  If you turn tooltip mode
off, it is shown in the echo area; but this is only in a gui frame.

I think it is very important to show where a link goes in a document.  I
consider it good a safety practise (e.g. web browsers).  Hence my
attempt to implement this feature.  :)

Cheers,

-- 
Suvayu

Open source is the future. It sets us free.

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

* Re: Adding text properties to all Org mode links
  2013-07-14  6:41   ` Suvayu Ali
@ 2013-09-09 23:15     ` Suvayu Ali
  2013-09-10  6:56       ` Jambunathan K
  0 siblings, 1 reply; 8+ messages in thread
From: Suvayu Ali @ 2013-09-09 23:15 UTC (permalink / raw)
  To: emacs-orgmode

Hello again everyone,

On Sun, Jul 14, 2013 at 08:41:25AM +0200, Suvayu Ali wrote:
> On Sat, Jul 13, 2013 at 11:01:08PM -0400, Nick Dokos wrote:
> > Suvayu Ali <fatkasuvayu+linux@gmail.com> writes:
> > >
> > > How do I add text properties to org elements?  In my particular case, I
> > > want to echo tooltips when I move my cursor over an org link (or other
> > > org elements for that matter).  To do this, I need to add the properties
> > > point-left and point-entered to all org-links.  How do I do that?
> > >
> > > Thanks for any ideas.
> > 
> > Not sure if this is the best method:
> > 
> > o go to (point-min)
> > o loop
> >      (goto-char (cdr (org-element-link-successor (point-max))))
> >      (org-element-link-parser) and extract :begin and :end values from
> >      the returned list
> > 
> > Untested (mostly) - termination, error handling (and who knows what
> > else) left to the interested reader...
> 
> I was afraid of this.  I think the safest way of not screwing up the
> parsing and error handling would be to implement it as a patch to
> org-activate-*-links in org.el.

I was taking a shot at this again.  This is where I stand at the moment:

- I want to add the properties `point-left' and `point-entered' to all
  links where the target is invisible (hidden), so for the moment I'm
  focusing on bracket links.
- I tried to patch `org-activate-bracket-links' to this end; in the let*
  bind I extended the list of properties with like this:

    (let* ((hl (org-match-string-no-properties 1))
           (help (concat "LINK: " (save-match-data (org-link-unescape hl))))
           (ip (org-maybe-intangible
      	  (list 'invisible 'org-link
      		'keymap org-mouse-map 'mouse-face 'highlight
      		'font-lock-multiline t 'help-echo help
      		'point-left sa-echo-tooltip       ; <-- my addition
      		'point-entered sa-echo-tooltip    ; <-- my addition
      		'htmlize-link `(:uri ,hl))))
           (vp (list 'keymap org-mouse-map 'mouse-face 'highlight
      	       'font-lock-multiline t 'help-echo help
      	       'point-left sa-echo-tooltip        ; <-- my addition
      	       'point-entered sa-echo-tooltip     ; <-- my addition
      	       'htmlize-link `(:uri ,hl))))
      ;; rest of the code is unchanged
      )

With this "new" org-activate-bracket-links, when I open an Org file, I
see some bad fontification (e.g. keywords are in default face) and the
invisible parts of backet links are visible.  As in: instead of showing

  this is a link 
  (in org-link face)

I see

  [[http://www.example.com/target][this is a link]]
  (the http part is in org-link face, the rest in default)

I tried to run edebug-defun on org-activate-bracket-links before opening
the org file, but that doesn't trigger the step by step execution of
org-activate-bracket-links I was expecting.  I tested with
`get-text-property' interactively, my properties were not added to the
links.  So I'm wondering what am I doing wrong?  Better yet, is there a
better way to do this?

Thanks for any help or ideas.

Cheers,

-- 
Suvayu

Open source is the future. It sets us free.

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

* Re: Adding text properties to all Org mode links
  2013-09-09 23:15     ` Suvayu Ali
@ 2013-09-10  6:56       ` Jambunathan K
  2013-09-10 11:39         ` Suvayu Ali
  0 siblings, 1 reply; 8+ messages in thread
From: Jambunathan K @ 2013-09-10  6:56 UTC (permalink / raw)
  To: Suvayu Ali; +Cc: emacs-orgmode


Add salt to taste or cookup your own recipe based on the hints here.

(add-hook 'org-mode-hook
	  (lambda nil
	    (setq-local default-text-properties
			'(point-entered org-link-entered-maybe))))

(defun org-link-entered-maybe (op np)
  (when (derived-mode-p 'org-mode)
    ;; (message "In org-link-entered-maybe")
    (let* ((inhibit-point-motion-hooks t)
	   (ctx (org-element-context)))
      (when (eq 'link (org-element-type ctx))
	(tooltip-show (org-element-property :raw-link ctx)
		      (not 'use-echo-area))))))

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

* Re: Adding text properties to all Org mode links
  2013-09-10  6:56       ` Jambunathan K
@ 2013-09-10 11:39         ` Suvayu Ali
  2013-09-10 12:09           ` Jambunathan K
  0 siblings, 1 reply; 8+ messages in thread
From: Suvayu Ali @ 2013-09-10 11:39 UTC (permalink / raw)
  To: Jambunathan K; +Cc: emacs-orgmode

Hi Jambu,

On Tue, Sep 10, 2013 at 12:26:22PM +0530, Jambunathan K wrote:
> 
> Add salt to taste or cookup your own recipe based on the hints here.
> 
> (add-hook 'org-mode-hook
> 	  (lambda nil
> 	    (setq-local default-text-properties
> 			'(point-entered org-link-entered-maybe))))
> 
> (defun org-link-entered-maybe (op np)
>   (when (derived-mode-p 'org-mode)
>     ;; (message "In org-link-entered-maybe")
>     (let* ((inhibit-point-motion-hooks t)
> 	   (ctx (org-element-context)))
>       (when (eq 'link (org-element-type ctx))
> 	(tooltip-show (org-element-property :raw-link ctx)
> 		      (not 'use-echo-area))))))

I can't see the properties.  This is what I tried:

(add-hook 'org-mode-hook
	  (lambda nil
	    ;; (setq-local default-text-properties
	    ;; 		'(point-entered org-link-entered-maybe point-left org-link-entered-maybe))
	    (setq-local default-text-properties
			'(point-entered sa-echo-tooltip point-left sa-echo-tooltip))
	    ))

Where sa-echo-tooltip is my function.  Then I open the following Org
file:

------8<---------8<----------
#+TITLE: Test adding text properties to links

#+STARTUP: showeverything

* Links
- [[https://www.google.com][Google]]
- https://en.wikipedia.org/wiki/Main_page
------8<---------8<----------

With my cursor on the 2 links, I see the following with describe-char:

There are text properties here:
  face                 org-link
  font-lock-multiline  t
  fontified            t
  help-echo            "LINK: https://www.google.com"
  htmlize-link         (:uri "https://www.google.com")
  keymap               [Show]
  mouse-face           highlight
  org-no-flyspell      t

There are text properties here:
  face                 org-link
  fontified            t
  htmlize-link         (:uri "https://en.wikipedia.org/wiki/Main_page")
  keymap               [Show]
  mouse-face           highlight
  org-no-flyspell      t

As you see there is no mention of point-left or point-entered.

Any ideas?

-- 
Suvayu

Open source is the future. It sets us free.

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

* Re: Adding text properties to all Org mode links
  2013-09-10 11:39         ` Suvayu Ali
@ 2013-09-10 12:09           ` Jambunathan K
  2013-09-10 12:24             ` Suvayu Ali
  0 siblings, 1 reply; 8+ messages in thread
From: Jambunathan K @ 2013-09-10 12:09 UTC (permalink / raw)
  To: Suvayu Ali; +Cc: emacs-orgmode

Suvayu Ali <fatkasuvayu+linux@gmail.com> writes:

> I can't see the properties.  This is what I tried:

Did something happen with my snippet?  I see a tooltip (which is placed
afar from the link in question) in my machine.

> (add-hook 'org-mode-hook
> 	  (lambda nil
> 	    ;; (setq-local default-text-properties
> 	    ;; 		'(point-entered org-link-entered-maybe point-left org-link-entered-maybe))
> 	    (setq-local default-text-properties
> 			'(point-entered sa-echo-tooltip point-left sa-echo-tooltip))
> 	    ))
>

point-entered and point-left properties should have different values.
See 

    (info "(elisp) Special Properties").

> As you see there is no mention of point-left or point-entered.

With point on the link try this:

    M-: (get-text-property (point) 'point-entered)


ps: There could be better way of gettting what you want.  Do your own
exploration.

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

* Re: Adding text properties to all Org mode links
  2013-09-10 12:09           ` Jambunathan K
@ 2013-09-10 12:24             ` Suvayu Ali
  0 siblings, 0 replies; 8+ messages in thread
From: Suvayu Ali @ 2013-09-10 12:24 UTC (permalink / raw)
  To: Jambunathan K; +Cc: emacs-orgmode

On Tue, Sep 10, 2013 at 05:39:58PM +0530, Jambunathan K wrote:
> Suvayu Ali <fatkasuvayu+linux@gmail.com> writes:
> 
> > I can't see the properties.  This is what I tried:
> 
> Did something happen with my snippet?  I see a tooltip (which is placed
> afar from the link in question) in my machine.

Sorry I think I wasn't clear in my email.  I want to echo in the echo
area.  So changing the (not 'use-echo-area) to 'use-echo-area did it.

> > (add-hook 'org-mode-hook
> > 	  (lambda nil
> > 	    ;; (setq-local default-text-properties
> > 	    ;; 		'(point-entered org-link-entered-maybe point-left org-link-entered-maybe))
> > 	    (setq-local default-text-properties
> > 			'(point-entered sa-echo-tooltip point-left sa-echo-tooltip))
> > 	    ))
> >
> 
> point-entered and point-left properties should have different values.
> See 
> 
>     (info "(elisp) Special Properties").

I had read that, but I think I misunderstood it the last time I read it.
After your message when I read it again, I see that they should be
different :-p.

Thanks a lot.  I'll experiment some more.

Cheers,

-- 
Suvayu

Open source is the future. It sets us free.

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

end of thread, other threads:[~2013-09-10 12:24 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-13 13:40 Adding text properties to all Org mode links Suvayu Ali
2013-07-14  3:01 ` Nick Dokos
2013-07-14  6:41   ` Suvayu Ali
2013-09-09 23:15     ` Suvayu Ali
2013-09-10  6:56       ` Jambunathan K
2013-09-10 11:39         ` Suvayu Ali
2013-09-10 12:09           ` Jambunathan K
2013-09-10 12:24             ` Suvayu Ali

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