From 37829312bac3372feb986f48f09f7d45d349d63d Mon Sep 17 00:00:00 2001 From: Michael Olson Date: Sat, 4 Nov 2006 05:43:47 +0000 Subject: [PATCH] Be smarter about where explicit interwiki links end 2006-11-04 Michael Olson * lisp/muse-wiki.el (muse-wiki-update-interwiki-regexp): Make page optional, and make interwiki delimiter a regular rather than shy group. (muse-wiki-handle-implicit-interwiki): Rename from muse-wiki-handle-interwiki. Use match group 3 to get the page. (muse-wiki-handle-explicit-interwiki): New function that is smarter about where an explicit link ends in a buffer. This allows you to refer to page names with invalid Wiki characters, such as underscores and dashes, merely by enclosing them in double brackets. git-archimport-id: mwolson@gnu.org--2006/muse--main--1.0--patch-240 --- ChangeLog | 13 +++++++++++++ lisp/muse-wiki.el | 46 ++++++++++++++++++++++++++++++++++++---------- 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9636311..459f3bd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2006-11-04 Michael Olson + + * lisp/muse-wiki.el (muse-wiki-update-interwiki-regexp): Make page + optional, and make interwiki delimiter a regular rather than shy + group. + (muse-wiki-handle-implicit-interwiki): Rename from + muse-wiki-handle-interwiki. Use match group 3 to get the page. + (muse-wiki-handle-explicit-interwiki): New function that is + smarter about where an explicit link ends in a buffer. This + allows you to refer to page names with invalid Wiki characters, + such as underscores and dashes, merely by enclosing them in double + brackets. + 2006-11-03 Michael Olson * lisp/muse-project.el (muse-project-page-file): Make relative diff --git a/lisp/muse-wiki.el b/lisp/muse-wiki.el index 39984d9..a617b56 100644 --- a/lisp/muse-wiki.el +++ b/lisp/muse-wiki.el @@ -165,7 +165,7 @@ If you want this replacement to happen, you must add muse-wiki-interwiki-alist))) (when interwiki-rules (concat "\\|" (regexp-opt interwiki-rules))))) - "\\)\\(?:\\(?:" muse-wiki-interwiki-delimiter + "\\)\\(?:\\(" muse-wiki-interwiki-delimiter "\\)\\(" (when muse-wiki-match-all-project-files ;; append the files from the project @@ -177,7 +177,7 @@ If you want this replacement to happen, you must add files))) (when files (concat (regexp-opt files) "\\|")))) - "\\sw+\\)\\)?\\>")) + "\\sw+\\)?\\)?\\>")) (when (featurep 'muse-colors) (muse-configure-highlighting 'muse-colors-markup muse-colors-markup)))) @@ -256,7 +256,7 @@ use the first style we find." (concat page-path "." muse-file-extension) page-path))))))) -(defun muse-wiki-handle-interwiki (&optional string) +(defun muse-wiki-handle-implicit-interwiki (&optional string) "If STRING or point has an interwiki link, resolve it and return the first match. @@ -267,9 +267,9 @@ Match 2 is set to the description." (let* ((project (match-string 1 string)) (subst (cdr (assoc project muse-wiki-interwiki-alist))) (word (if string - (and (match-beginning 2) - (substring string (match-beginning 2))) - (match-string 2 string)))) + (and (match-beginning 3) + (substring string (match-beginning 3))) + (match-string 3 string)))) (if subst (if (functionp subst) (funcall subst word) @@ -278,6 +278,32 @@ Match 2 is set to the description." (or word (not muse-wiki-ignore-bare-project-names)) (muse-wiki-resolve-project-page project word)))))) +(defun muse-wiki-handle-explicit-interwiki (&optional string) + "If STRING or point has an interwiki link, resolve it and +return the first match. + +Match 1 is set to the link. +Match 2 is set to the description." + (let ((right-pos (unless string (match-end 1)))) + (when (if string (string-match muse-wiki-interwiki-regexp string) + (looking-at muse-wiki-interwiki-regexp)) + (let* ((project (match-string 1 string)) + (subst (cdr (assoc project muse-wiki-interwiki-alist))) + (word (if right-pos + (and (match-end 2) + (buffer-substring (match-end 2) right-pos)) + (if string + (and (match-beginning 3) + (substring string (match-beginning 3))) + (match-string 3 string))))) + (if subst + (if (functionp subst) + (funcall subst word) + (concat subst word)) + (and (assoc project muse-project-alist) + (or word (not muse-wiki-ignore-bare-project-names)) + (muse-wiki-resolve-project-page project word))))))) + (defun muse-wiki-handle-wikiword (&optional string) "If STRING or point has a WikiWord, return it. @@ -412,20 +438,20 @@ If EXPLICIT is non-nil, TITLE will be returned unmodified." ;; Insinuate link handling (custom-add-option 'muse-implicit-link-functions - 'muse-wiki-handle-interwiki) + 'muse-wiki-handle-implicit-interwiki) (custom-add-option 'muse-implicit-link-functions 'muse-wiki-handle-wikiword) (custom-add-option 'muse-explicit-link-functions - 'muse-wiki-handle-interwiki) + 'muse-wiki-handle-explicit-interwiki) (add-to-list 'muse-implicit-link-functions - 'muse-wiki-handle-interwiki t) + 'muse-wiki-handle-implicit-interwiki t) (add-to-list 'muse-implicit-link-functions 'muse-wiki-handle-wikiword t) (add-to-list 'muse-explicit-link-functions - 'muse-wiki-handle-interwiki t) + 'muse-wiki-handle-explicit-interwiki t) ;; Obsolete functions -- 2.11.4.GIT