From 12a5052e13fe70f0a04a5c382bcd3d1a2534304f Mon Sep 17 00:00:00 2001 From: Michael Olson Date: Wed, 13 Jul 2005 21:12:27 +0000 Subject: [PATCH] Make published link handling do the right thing, plus misc. fixes. * lisp/muse-mode.el (muse-mode-hook): Add option for `muse-wiki-update-custom-values'. The :set function makes sure that this is always included in `muse-mode-hook' if muse-wiki is loaded. This probably isn't best-practice, but it works. * lisp/muse-project.el (muse-project-of-file): Fix some duplicated code. Save match data. * lisp/muse-publish.el (muse-publish-url-transforms): Add `muse-publish-prepare-url' to the listed options. * lisp/muse-publish.el (muse-publish-output-file): Handle case where output-dir is not specified. * lisp/muse-publish.el (muse-publish-markup-link): Call link handlers here instead of later on. * lisp/muse-wiki.el (muse-wiki-update-interwiki-regexp): Try to do the right thing when `muse-wiki-interwiki-alist' is nil. * lisp/muse-wiki.el (muse-wiki-output-name): Removed in favor of calling `muse-publish-output-file'. * lisp/muse-wiki.el (muse-wiki-transform-interwiki) (muse-wiki-transform-wikiword): Removed. We should not use the publishing transforms facility to handle these. * lisp/muse-wiki.el ("muse-publish"): Publish wikiwords and interwiki links as "link" rather than "url". * lisp/muse-wiki.el (muse-wiki-update-custom-values): New function that takes care of any customization cleaups that need to happen whenever muse-mode is entered. * lisp/muse.el (muse-implicit-link-functions): Add options for `muse-handle-url' and the wiki handlers. (muse-explicit-link-functions): Add option for `muse-wiki-handle-internal'. git-archimport-id: mwolson@gnu.org--2005/muse--main--1.0--patch-133 --- ChangeLog | 51 ++++++++++++++++++++++++++++++++++++++++++ lisp/muse-mode.el | 7 +++++- lisp/muse-project.el | 36 ++++++++++++++++-------------- lisp/muse-publish.el | 25 +++++++++++++++------ lisp/muse-wiki.el | 63 +++++++++++++--------------------------------------- lisp/muse.el | 4 ++++ 6 files changed, 113 insertions(+), 73 deletions(-) diff --git a/ChangeLog b/ChangeLog index e4c0f61..74bd277 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,57 @@ # arch-tag: automatic-ChangeLog--mwolson@gnu.org--2005/muse--main--1.0 # +2005-07-13 21:12:27 GMT Michael Olson patch-133 + + Summary: + Make published link handling do the right thing, plus misc. fixes. + Revision: + muse--main--1.0--patch-133 + + * lisp/muse-mode.el (muse-mode-hook): Add option for + `muse-wiki-update-custom-values'. The :set function makes sure that + this is always included in `muse-mode-hook' if muse-wiki is loaded. + This probably isn't best-practice, but it works. + + * lisp/muse-project.el (muse-project-of-file): Fix some duplicated code. + Save match data. + + * lisp/muse-publish.el (muse-publish-url-transforms): Add + `muse-publish-prepare-url' to the listed options. + + * lisp/muse-publish.el (muse-publish-output-file): Handle case where + output-dir is not specified. + + * lisp/muse-publish.el (muse-publish-markup-link): Call link handlers + here instead of later on. + + * lisp/muse-wiki.el (muse-wiki-update-interwiki-regexp): Try to do the + right thing when `muse-wiki-interwiki-alist' is nil. + + * lisp/muse-wiki.el (muse-wiki-output-name): Removed in favor of calling + `muse-publish-output-file'. + + * lisp/muse-wiki.el (muse-wiki-transform-interwiki) + (muse-wiki-transform-wikiword): Removed. We should not use the + publishing transforms facility to handle these. + + * lisp/muse-wiki.el ("muse-publish"): Publish wikiwords and interwiki + links as "link" rather than "url". + + * lisp/muse-wiki.el (muse-wiki-update-custom-values): New function that + takes care of any customization cleaups that need to happen whenever + muse-mode is entered. + + * lisp/muse.el (muse-implicit-link-functions): Add options for + `muse-handle-url' and the wiki handlers. + (muse-explicit-link-functions): Add option for + `muse-wiki-handle-internal'. + + modified files: + ChangeLog lisp/muse-mode.el lisp/muse-project.el + lisp/muse-publish.el lisp/muse-wiki.el lisp/muse.el + + 2005-07-13 03:38:52 GMT Michael Olson patch-132 Summary: diff --git a/lisp/muse-mode.el b/lisp/muse-mode.el index a1ed723..1877d85 100644 --- a/lisp/muse-mode.el +++ b/lisp/muse-mode.el @@ -86,7 +86,12 @@ so only enable this if you don't use either of these." "A hook that is run when Muse mode is entered." :type 'hook :options '(flyspell-mode footnote-mode turn-on-auto-fill - highlight-changes-mode) + highlight-changes-mode + muse-wiki-update-custom-values) + :set #'(lambda (sym val) + (when (featurep 'muse-wiki) + (add-to-list 'val 'muse-wiki-update-custom-values)) + (set sym val)) :group 'muse-mode) (defvar muse-mode-map diff --git a/lisp/muse-project.el b/lisp/muse-project.el index f907708..36c9d63 100644 --- a/lisp/muse-project.el +++ b/lisp/muse-project.el @@ -262,26 +262,28 @@ disk." If PATHNAME is nil, the current buffer's filename is used." (if (and (null pathname) muse-current-project) muse-current-project - (when (or pathname - (and (boundp 'muse-publishing-current-file) - muse-publishing-current-file) - buffer-file-name) - (let* ((file (file-truename (or pathname buffer-file-name))) + (setq pathname (or pathname + (and (boundp 'muse-publishing-current-file) + muse-publishing-current-file) + buffer-file-name)) + (when pathname + (let* ((file (file-truename pathname)) (dir (file-name-directory file)) (project-entry muse-project-alist) found) - (while (and project-entry (not found)) - (let ((pats (car (cdar project-entry)))) - (while (and pats (not found)) - (if (symbolp (car pats)) - (setq pats (cddr pats)) - (let ((truename (file-truename (car pats)))) - (if (or (string= truename file) - (string= truename dir) - (string-match truename file)) - (setq found (car project-entry)))) - (setq pats (cdr pats)))) - (setq project-entry (cdr project-entry)))) + (save-match-data + (while (and project-entry (not found)) + (let ((pats (car (cdar project-entry)))) + (while (and pats (not found)) + (if (symbolp (car pats)) + (setq pats (cddr pats)) + (let ((truename (file-truename (car pats)))) + (if (or (string= truename file) + (string= truename dir) + (string-match truename file)) + (setq found (car project-entry)))) + (setq pats (cdr pats)))) + (setq project-entry (cdr project-entry))))) found)))) (defun muse-read-project (prompt &optional no-check-p no-assume) diff --git a/lisp/muse-publish.el b/lisp/muse-publish.el index 67443dc..09ff239 100644 --- a/lisp/muse-publish.el +++ b/lisp/muse-publish.el @@ -56,6 +56,7 @@ See `muse-publish' for more information." "A list of functions used to prepare URLs for publication. Each is passed the URL and expects a URL to be returned." :type 'hook + :options '(muse-publish-prepare-url) :group 'muse-publish) (defcustom muse-publish-report-threshhold 100000 @@ -513,9 +514,12 @@ contents were requested.") (muse-page-name file) (muse-style-element :suffix style))) -(defsubst muse-publish-output-file (file output-dir &optional style) +(defsubst muse-publish-output-file (file &optional output-dir style) (setq style (muse-style style)) - (expand-file-name (muse-publish-output-name file style) output-dir)) + (if output-dir + (expand-file-name (muse-publish-output-name file style) output-dir) + (concat (file-name-directory file) + (muse-publish-output-name file style)))) (defun muse-publish-file (file style &optional output-dir force) "Publish the given file in list FILES. @@ -946,11 +950,18 @@ like read-only from being inadvertently deleted." (muse-publish-mark-read-only beg (point)))) (defun muse-publish-markup-link () - (let ((explicit (save-match-data - (if (string-match muse-explicit-link-regexp - (match-string 0)) - t nil)))) - (muse-publish-insert-url (match-string 1) (match-string 2) explicit))) + (let* ((explicit (save-match-data + (if (string-match muse-explicit-link-regexp + (match-string 0)) + t nil))) + (link (if explicit + (progn + (goto-char (match-beginning 1)) + (muse-handle-explicit-link)) + (goto-char (match-beginning 0)) + (muse-handle-implicit-link)))) + (when link + (muse-publish-insert-url link (match-string 2) explicit)))) (defun muse-publish-markup-url () (muse-publish-insert-url (match-string 0))) diff --git a/lisp/muse-wiki.el b/lisp/muse-wiki.el index 1cde273..272d33c 100644 --- a/lisp/muse-wiki.el +++ b/lisp/muse-wiki.el @@ -65,13 +65,12 @@ This is automatically generated by setting `muse-wiki-interwiki-alist'. It can also be set by calling `muse-wiki-update-interwiki-regexp'.") (defun muse-wiki-update-interwiki-regexp (value) - "Update the value of `muse-wiki-interwiki-regexp'." - (if value - (setq muse-wiki-interwiki-regexp - (concat "\\<\\(" (mapconcat 'car muse-project-alist "\\|") - "\\|" (mapconcat 'car value "\\|") - "\\)\\(?:\\(?:#\\|::\\)\\(\\sw+\\)\\)?\\>")) - (setq muse-wiki-interwiki-regexp "")) + "Update the value of `muse-wiki-interwiki-regexp' based on VALUE +and `muse-project-alist'." + (setq muse-wiki-interwiki-regexp + (concat "\\<\\(" (mapconcat 'car muse-project-alist "\\|") + (when value (concat "\\|" (mapconcat 'car value "\\|"))) + "\\)\\(?:\\(?:#\\|::\\)\\(\\sw+\\)\\)?\\>")) (muse-configure-highlighting 'muse-colors-markup muse-colors-markup)) (defcustom muse-wiki-interwiki-alist @@ -109,37 +108,6 @@ this." (set sym value))) :group 'muse-wiki) -(defun muse-wiki-output-name (name) - "Much like `muse-publish-output-name', but keep the directory part." - (concat (file-name-directory name) - (muse-publish-output-name name))) - -(defun muse-wiki-transform-interwiki (url explicit) - "Return the destination of the given URL if it is an interwiki link. -Otherwise return URL. Read-only properties are added to the string." - (let ((res (muse-wiki-handle-interwiki url))) - (if (and res (not (string-match muse-image-regexp res))) - (setq url (muse-wiki-output-name res)))) - url) - -(defun muse-wiki-transform-wikiword (url explicit) - "If URL is a WikiWord but does not correspond with an existing -file or interwiki name, return nil. Otherwise, return URL. -Read-only properties are added to the string." - (when (and muse-wiki-use-wikiword - (not explicit) - (string-match (concat "^" muse-wiki-wikiword-regexp "$") url)) - (unless (or (and (muse-project-of-file) - (muse-project-page-file - url muse-current-project t)) - (file-exists-p url) - ;; This is allowed to be the name of an interwiki or - ;; the name of a project. - (assoc url muse-project-alist) - (assoc url muse-wiki-interwiki-alist)) - (setq url nil))) - url) - (defun muse-wiki-resolve-project-page (&optional project page) "Return the published path from the current page to PAGE of PROJECT. If PAGE is not specified, use the value of :default in PROJECT. @@ -269,15 +237,11 @@ called manually." (eval-after-load "muse-publish" '(progn (add-to-list 'muse-publish-markup-regexps - '(3100 muse-wiki-interwiki-regexp 0 url) + '(3100 muse-wiki-interwiki-regexp 0 link) t) (add-to-list 'muse-publish-markup-regexps - '(3200 muse-wiki-wikiword-regexp 0 url) - t) - (add-to-list 'muse-publish-url-transforms - 'muse-wiki-transform-interwiki) - (add-to-list 'muse-publish-url-transforms - 'muse-wiki-transform-wikiword))) + '(3200 muse-wiki-wikiword-regexp 0 link) + t))) ;; Insinuate link handling @@ -287,12 +251,15 @@ called manually." 'muse-wiki-handle-wikiword t) (add-to-list 'muse-explicit-link-functions - 'muse-wiki-handle-interwiki) + 'muse-wiki-handle-interwiki t) ;; Update several things when Muse mode is entered +(defun muse-wiki-update-custom-values () + "Update some important muse-wiki values that may have been altered manually." + (muse-wiki-update-interwiki-regexp muse-wiki-interwiki-alist)) + (add-hook 'muse-mode-hook - #'(lambda nil - (muse-wiki-update-interwiki-regexp muse-wiki-interwiki-alist))) + 'muse-wiki-update-custom-values) (provide 'muse-wiki) ;;; muse-wiki.el ends here diff --git a/lisp/muse.el b/lisp/muse.el index dfaa46b..58598b1 100644 --- a/lisp/muse.el +++ b/lisp/muse.el @@ -274,6 +274,9 @@ An implicit link is one that is not surrounded by brackets. By default, Muse handles URLs only. If you want to handle WikiWords, load muse-wiki.el." :type '(repeat function) + :options '(muse-handle-url + muse-wiki-handle-interwiki + muse-wiki-handle-wikiword) :group 'muse) (defun muse-handle-implicit-link (&optional link) @@ -308,6 +311,7 @@ that is an accepted link." "A list of functions to handle an explicit link. An explicit link is one [[like][this]] or [[this]]." :type '(repeat function) + :options '(muse-wiki-handle-interwiki) :group 'muse) (defun muse-handle-explicit-link (&optional link) -- 2.11.4.GIT