From 55c0708bc40c1fccf5ca7a6b82a1bbeb89a0b99e Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Tue, 3 Feb 2015 23:00:21 +0100 Subject: [PATCH] org-element: Externalize docview links * lisp/org-element.el (org-element-link-type-is-file): Remove. (org-element-link-parser): Do not treat specially anymore "docview" link type. * testing/lisp/test-org-element.el (test-org-element/link-parser): Update test. * lisp/org-docview.el (org-docview-export): Fix path. "docview" is a custom link type handled in its own library. There is no reason to include it in core parser. --- lisp/org-docview.el | 6 +++--- lisp/org-element.el | 24 ++++++------------------ testing/lisp/test-org-element.el | 6 +++--- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/lisp/org-docview.el b/lisp/org-docview.el index b90726225..479f4ffc4 100644 --- a/lisp/org-docview.el +++ b/lisp/org-docview.el @@ -1,6 +1,6 @@ ;;; org-docview.el --- support for links to doc-view-mode buffers -;; Copyright (C) 2009-2014 Free Software Foundation, Inc. +;; Copyright (C) 2009-2015 Free Software Foundation, Inc. ;; Author: Jan Böcker ;; Keywords: outlines, hypermedia, calendar, wp @@ -54,8 +54,8 @@ (defun org-docview-export (link description format) "Export a docview link from Org files." - (let* ((path (when (string-match "\\(.+\\)::.+" link) - (match-string 1 link))) + (let* ((path (if (string-match "\\(.+\\)::.+" link) (match-string 1 link) + link)) (desc (or description link))) (when (stringp path) (setq path (org-link-escape (expand-file-name path))) diff --git a/lisp/org-element.el b/lisp/org-element.el index b92dd6af8..7a73faee0 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -1,6 +1,6 @@ ;;; org-element.el --- Parser And Applications for Org syntax -;; Copyright (C) 2012-2014 Free Software Foundation, Inc. +;; Copyright (C) 2012-2015 Free Software Foundation, Inc. ;; Author: Nicolas Goaziou ;; Keywords: outlines, hypermedia, calendar, wp @@ -260,12 +260,6 @@ specially in `org-element--object-lex'.") Names must be uppercase. Any block whose name has no association is parsed with `org-element-special-block-parser'.") -(defconst org-element-link-type-is-file - '("file" "file+emacs" "file+sys" "docview") - "List of link types equivalent to \"file\". -Only these types can accept search options and an explicit -application to open them.") - (defconst org-element-affiliated-keywords '("CAPTION" "DATA" "HEADER" "HEADERS" "LABEL" "NAME" "PLOT" "RESNAME" "RESULT" "RESULTS" "SOURCE" "SRCNAME" "TBLNAME") @@ -3071,22 +3065,16 @@ Assume point is at the beginning of the link." (save-excursion (setq post-blank (progn (goto-char link-end) (skip-chars-forward " \t")) end (point)) - ;; Special "file" type link processing. - (when (member type org-element-link-type-is-file) - ;; Extract opening application and search option. - (cond ((string-match "^file\\+\\(.*\\)$" type) - (setq application (match-string 1 type))) - ((not (string-match "^file" type)) - (setq application type))) + ;; Special "file" type link processing. Extract opening + ;; application and search option, if any. Also normalize URI. + (when (string-match "\\`file\\(?:\\+\\(.+\\)\\)?\\'" type) + (setq application (match-string 1 type) type "file") (when (string-match "::\\(.*\\)\\'" path) (setq search-option (match-string 1 path) path (replace-match "" nil nil path))) - ;; Normalize URI. (when (and (file-name-absolute-p path) (not (org-string-match-p "\\`[/~]/" path))) - (setq path (concat "//" path))) - ;; Make sure TYPE always reports "file". - (setq type "file")) + (setq path (concat "//" path)))) (list 'link (list :type type :path path diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el index 97e88e647..c9ae6c82c 100644 --- a/testing/lisp/test-org-element.el +++ b/testing/lisp/test-org-element.el @@ -1,6 +1,6 @@ ;;; test-org-element.el --- Tests for org-element.el -;; Copyright (C) 2012, 2013, 2014 Nicolas Goaziou +;; Copyright (C) 2012-2015 Nicolas Goaziou ;; Author: Nicolas Goaziou @@ -1495,8 +1495,8 @@ e^{i\\pi}+1=0 (require 'org-docview) (should (equal - '("file" "projects.org" "docview") - (org-test-with-temp-text "[[docview:projects.org]]" + '("file" "projects.org" "emacs") + (org-test-with-temp-text "[[file+emacs:projects.org]]" (let ((l (org-element-context))) (list (org-element-property :type l) (org-element-property :path l) -- 2.11.4.GIT