emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* patch for custom colored links in org-mode
@ 2016-06-26 13:35 John Kitchin
  2016-06-27 12:52 ` Christian Wittern
  2016-06-28 14:46 ` Nicolas Goaziou
  0 siblings, 2 replies; 21+ messages in thread
From: John Kitchin @ 2016-06-26 13:35 UTC (permalink / raw)
  To: org mode

Hi all,

I tried this aproach to enable custom colored links in org-mode if an
org-link-type face is defined. If no face is applied, then it just gets
the default org-link face

For example this will make all doi links red.

(defface org-link-doi
  `((t (:inherit org-link
                 :foreground "red")))
  "Color for doi links.")

It seems to work pretty well for me. What do you think about making this
a feature in org-mode?

diff --git a/lisp/org.el b/lisp/org.el
index af68539..f1c500d 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -5851,14 +5851,19 @@ prompted for."
   "Add link properties for plain links."
   (when (and (re-search-forward org-plain-link-re limit t)
             (not (org-in-src-block-p)))
-    (let ((face (get-text-property (max (1- (match-beginning 0)) (point-min))
-                                  'face))
-         (link (org-match-string-no-properties 0)))
+    (let* ((face (get-text-property (max (1- (match-beginning 0)) (point-min))
+                                   'face))
+          (link (org-match-string-no-properties 0))
+          (type (org-match-string-no-properties 1))
+          (link-face-symbol (intern (format "org-link-%s" type)))
+          (link-face (if (facep link-face-symbol)
+                         link-face-symbol
+                       'org-link)))
       (unless (if (consp face) (memq 'org-tag face) (eq 'org-tag face))
        (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
        (add-text-properties (match-beginning 0) (match-end 0)
                             (list 'mouse-face 'highlight
-                                  'face 'org-link
+                                  'face link-face
                                   'htmlize-link `(:uri ,link)
                                   'keymap org-mouse-map))
        (org-rear-nonsticky-at (match-end 0))
@@ -6340,8 +6345,8 @@ needs to be inserted at a specific position in the font-lock sequence.")
           ;; Links
           (if (memq 'tag lk) '(org-activate-tags (1 'org-tag prepend)))
           (if (memq 'angle lk) '(org-activate-angle-links (0 'org-link t)))
-          (if (memq 'plain lk) '(org-activate-plain-links (0 'org-link t)))
-          (if (memq 'bracket lk) '(org-activate-bracket-links (0 'org-link t)))
+          (if (memq 'plain lk) '(org-activate-plain-links (0 'org-link)))
+          (if (memq 'bracket lk) '(org-activate-bracket-links (0 'org-link)))
           (if (memq 'radio lk) '(org-activate-target-links (1 'org-link t)))
           (if (memq 'date lk) '(org-activate-dates (0 'org-date t)))
           (if (memq 'footnote lk) '(org-activate-footnote-links))


-- 
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 related	[flat|nested] 21+ messages in thread
* Re: patch for custom colored links in org-mode
@ 2016-07-02  0:51 John Kitchin
  0 siblings, 0 replies; 21+ messages in thread
From: John Kitchin @ 2016-07-02  0:51 UTC (permalink / raw)
  To: John Kitchin, emacs-orgmode@gnu org, Rasmus

If there is no urgency I will take a shot at it next week. I will look through the code and come up with a detailed plan that expands on your 4 steps below and be in touch about it. Thanks in advance for your patience 😉.

On July 1, 2016, at 7:20 PM, Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:

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

> I agree, it doesn't make sense to use it for customization. OTOH, it
> also adds the link type to org-link-types, rebuilds the regexp and the
> org-link-protocols.

It is possible to rebuild regexps upon modifying a defcustom.

> Do you think we would eliminate `org-link-types' and
> `org-link-protocols' then? That would be fine with me.

They would contain duplicate data, so they can be removed.

> I think we might still want an org-add-link-type function though, if
> there are additional things that need to be done after adding to
> `org-link-type-parameters', e.g. updating regexps. It might even be
> feasible to keep backward compatibility for code that already uses
> this.

We already have `org-make-link-regexp'. We can make it call
`org-element-update-syntax' at its end, so as to become a replacement
for `org-add-link-type'.

Every customization of `org-link-parameters' would then call
`org-make-link-regexp'. Users setting the variable by hand, or libraries
defining new types, would be required to call it explicitly, though.

I'm not sure about `org-add-link-type'. It introduces yet another way to
configure link, but makes possible to eschew the `org-make-link-regexp'
call. In any case, it needs to be kept around for
backward-compatibility, but could also be marked as obsolete, pointing
to `org-link-parameters' instead.

WDYT?

> Presumably we would then eliminate the "org-%s-complete-link"
> functions?

Indeed.

I think it is possible to proceed in four steps.

1. First, we create the variable, with appropriate getter, setter and
   default values. At this point it is sufficient to
   support :follow, :export and :completion properties only.

2. Then we get all the code base to extract information about links
   through this variable instead of various existing ways, namely,
   `org-%s-complete-link', `org-link-protocols' and `org-link-types'.

3. Then we extend it with new properties, i.e., :display, :echo
   and :face.

4. Document the changes in the manual and ORG-NEWS file.

You have mostly worked out the third part of the process. Do you want to
take a stab at any of the other steps? Or do you prefer me to do some
parts?

Regards,

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

end of thread, other threads:[~2016-07-06 11:30 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-26 13:35 patch for custom colored links in org-mode John Kitchin
2016-06-27 12:52 ` Christian Wittern
2016-06-28 14:46 ` Nicolas Goaziou
2016-06-28 18:34   ` Thomas S. Dye
2016-06-28 19:23   ` Rasmus
2016-06-28 20:11     ` Nicolas Goaziou
2016-06-28 20:27       ` Rasmus
2016-06-28 20:44         ` John Kitchin
2016-07-01 23:23         ` Nicolas Goaziou
2016-07-06 11:25           ` Rasmus
2016-06-28 20:42       ` John Kitchin
2016-07-01 12:51         ` Nicolas Goaziou
2016-07-01 17:20           ` John Kitchin
2016-07-01 23:20             ` Nicolas Goaziou
2016-07-02 15:46               ` John Kitchin
2016-07-02 22:17                 ` Nicolas Goaziou
2016-07-03 20:57               ` John Kitchin
2016-06-29  0:44   ` John Kitchin
2016-06-30 11:58     ` Nicolas Goaziou
2016-06-30 17:44       ` John Kitchin
  -- strict thread matches above, loose matches on Subject: below --
2016-07-02  0:51 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).