Skip to content

Commit

Permalink
Allow transform function for link descriptions. Bare email and URL fi…
Browse files Browse the repository at this point in the history
…xes.

* lisp/muse-publish.el (muse-publish-url-transforms): Docfix.
  (muse-publish-desc-transforms): New option that contains the functions
  that will be called to transform a link description.
  (muse-publish-markup-word): Handle Yet Another Edge Case.
  (muse-publish-markup-email): Use
  `muse-publish-escape-specials-in-string'.  Don't publish if we have a
  double-quote on either side.
  (muse-publish-url): Apply description transforms.
  (muse-publish-markup-url): Don't publish if we have a double-quote on
  either side.

* lisp/muse-wiki.el (muse-wiki-update-wikiword-regexp)
  (muse-wiki-wikiword-regexp, muse-wiki-use-wikiword): Minor docfixes.
  (muse-wiki-interwiki-delimiter): New option that indicates the
  interwiki delimiter to use.
  (muse-wiki-interwiki-replacement): New option that indicates the
  replacement
  (muse-wiki-update-interwiki-regexp): Use muse-wiki-interwiki-delimiter.
  (muse-wiki-publish-pretty-title): Deal with EXPLICIT argument so that
  this can be added to muse-publish-desc-transforms.
  (muse-wiki-publish-pretty-interwiki): New function that replaces the
  interwiki delimiter with its replacement, but only when the given text
  is not an explicit link.

* lisp/muse.el (muse-update-file-extension): New function made from the
  innards of the :set function in `muse-file-extension'.
git-archimport-id: mwolson@gnu.org--2005/muse--main--1.0--patch-185
  • Loading branch information
mwolson committed Jul 26, 2005
1 parent dc2d93e commit 7ffe752
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 54 deletions.
38 changes: 38 additions & 0 deletions ChangeLog
Expand Up @@ -2,6 +2,44 @@
# arch-tag: automatic-ChangeLog--mwolson@gnu.org--2005/muse--main--1.0
#

2005-07-26 08:03:41 GMT Michael Olson <mwolson@gnu.org> patch-185

Summary:
Allow transform function for link descriptions. Bare email and URL fixes.
Revision:
muse--main--1.0--patch-185

* lisp/muse-publish.el (muse-publish-url-transforms): Docfix.
(muse-publish-desc-transforms): New option that contains the functions
that will be called to transform a link description.
(muse-publish-markup-word): Handle Yet Another Edge Case.
(muse-publish-markup-email): Use
`muse-publish-escape-specials-in-string'. Don't publish if we have a
double-quote on either side.
(muse-publish-url): Apply description transforms.
(muse-publish-markup-url): Don't publish if we have a double-quote on
either side.

* lisp/muse-wiki.el (muse-wiki-update-wikiword-regexp)
(muse-wiki-wikiword-regexp, muse-wiki-use-wikiword): Minor docfixes.
(muse-wiki-interwiki-delimiter): New option that indicates the
interwiki delimiter to use.
(muse-wiki-interwiki-replacement): New option that indicates the
replacement
(muse-wiki-update-interwiki-regexp): Use muse-wiki-interwiki-delimiter.
(muse-wiki-publish-pretty-title): Deal with EXPLICIT argument so that
this can be added to muse-publish-desc-transforms.
(muse-wiki-publish-pretty-interwiki): New function that replaces the
interwiki delimiter with its replacement, but only when the given text
is not an explicit link.

* lisp/muse.el (muse-update-file-extension): New function made from the
innards of the :set function in `muse-file-extension'.

modified files:
ChangeLog lisp/muse-publish.el lisp/muse-wiki.el lisp/muse.el


2005-07-26 06:17:31 GMT Michael Olson <mwolson@gnu.org> patch-184

Summary:
Expand Down
41 changes: 27 additions & 14 deletions lisp/muse-publish.el
Expand Up @@ -55,15 +55,25 @@ See `muse-publish' for more information."
:type 'hook
:group 'muse-publish)

(defcustom muse-publish-url-transforms '(muse-publish-escape-specials-in-string
muse-publish-prepare-url)
(defcustom muse-publish-url-transforms
'(muse-publish-escape-specials-in-string
muse-publish-prepare-url)
"A list of functions used to prepare URLs for publication.
Each is passed the URL and expects a URL to be returned."
Each is passed the URL. The transformed URL should be returned."
:type 'hook
:options '(muse-publish-escape-specials-in-string
muse-publish-prepare-url)
:group 'muse-publish)

(defcustom muse-publish-desc-transforms
'(muse-publish-escape-specials-in-string)
"A list of functions used to prepare URL desciptions for publication.
Each is passed the description. The modified description should
be returned."
:type 'hook
:options '(muse-publish-escape-specials-in-string)
:group 'muse-publish)

(defcustom muse-publish-report-threshhold 100000
"If a file is this size or larger, report publishing progress."
:type 'integer
Expand Down Expand Up @@ -705,7 +715,7 @@ If IGNORE-READ-ONLY is non-nil, ignore the read-only property."
close-tag (muse-markup-text 'end-most-emph)))))))
(if (and (not (get-text-property beg 'noemphasis))
(setq loc (search-forward leader nil t))
(not (eq (char-syntax (char-after loc)) ?w))
(or (eobp) (not (eq (char-syntax (char-after loc)) ?w)))
(not (eq (char-syntax (char-before (point))) ?\ ))
(not (get-text-property (point) 'noemphasis)))
(progn
Expand Down Expand Up @@ -949,14 +959,13 @@ like read-only from being inadvertently deleted."
(defun muse-publish-markup-email ()
(let* ((beg (match-end 1))
(addr (buffer-substring-no-properties beg (match-end 0))))
(muse-with-temp-buffer
(insert addr)
(muse-publish-escape-specials (point-min) (point-max))
(setq addr (buffer-string)))
(goto-char beg)
(delete-region beg (match-end 0))
(insert (format (muse-markup-text 'email-addr) addr addr))
(muse-publish-mark-read-only beg (point))))
(when (not (or (eq (char-before (match-beginning 0)) ?\")
(eq (char-after (match-end 0)) ?\")))
(muse-publish-escape-specials-in-string addr)
(goto-char beg)
(delete-region beg (match-end 0))
(insert (format (muse-markup-text 'email-addr) addr addr))
(muse-publish-mark-read-only beg (point)))))

(defun muse-publish-escape-specials-in-string (string &rest ignored)
"Escape specials in STRING using style-specific :specials."
Expand All @@ -977,7 +986,9 @@ like read-only from being inadvertently deleted."
(let ((orig-url url))
(dolist (transform muse-publish-url-transforms)
(setq url (save-match-data (when url (funcall transform url explicit)))))
(setq desc (when desc (muse-publish-escape-specials-in-string desc)))
(dolist (transform muse-publish-desc-transforms)
(setq desc (save-match-data
(when desc (funcall transform desc explicit)))))
(if url
(cond ((string-match muse-image-regexp url)
(if desc
Expand Down Expand Up @@ -1016,7 +1027,9 @@ like read-only from being inadvertently deleted."
(muse-publish-insert-url link desc explicit))))

(defun muse-publish-markup-url ()
(muse-publish-insert-url (match-string 0)))
(when (not (or (eq (char-before (match-beginning 0)) ?\")
(eq (char-after (match-end 0)) ?\")))
(muse-publish-insert-url (match-string 0))))

;; Default publishing tags

Expand Down
84 changes: 60 additions & 24 deletions lisp/muse-wiki.el
Expand Up @@ -39,7 +39,7 @@
:group 'muse-mode)

(defun muse-wiki-update-wikiword-regexp (sym val)
"Update everything related to `muse-wiki-wikiword-regexp'"
"Update everything related to `muse-wiki-wikiword-regexp'."
(set sym val)
(if (featurep 'muse-colors)
(muse-configure-highlighting 'muse-colors-markup muse-colors-markup)))
Expand All @@ -53,13 +53,13 @@
(concat "\\<\\(\\(?:[" muse-regexp-upper
"][" muse-regexp-lower "]+\\)\\(?:["
muse-regexp-upper "][" muse-regexp-lower "]+\\)+\\)\\>")
"Regexp used to match WikiWords"
"Regexp used to match WikiWords."
:type 'regexp
:group 'muse-wiki
:set 'muse-wiki-update-wikiword-regexp)

(defcustom muse-wiki-use-wikiword t
"Wether to use WikiWord syntax or not"
"Whether to use color and publish bare WikiNames."
:type 'boolean
:group 'muse-wiki)

Expand All @@ -68,13 +68,30 @@
This is automatically generated by setting `muse-wiki-interwiki-alist'.
It can also be set by calling `muse-wiki-update-interwiki-regexp'.")

(defcustom muse-wiki-interwiki-delimiter "#\\|::"
"Delimiter regexp used for InterWiki links.
If you use groups, use only shy groups."
:type 'regexp
:group 'muse-wiki)

(defcustom muse-wiki-interwiki-replacement ": "
"Regexp used for replacing `muse-wiki-interwiki-delimiter' in
InterWiki link descriptions.
If you want this replacement to happen, you must add
`muse-wiki-publish-pretty-interwiki' to
`muse-publish-desc-transforms'."
:type 'regexp
:group 'muse-wiki)

(defun muse-wiki-update-interwiki-regexp (value)
"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-wiki-interwiki-delimiter
"\\)\\(\\sw+\\)\\)?\\>"))
(muse-configure-highlighting 'muse-colors-markup muse-colors-markup))

(defcustom muse-wiki-interwiki-alist
Expand Down Expand Up @@ -168,7 +185,7 @@ Match 1 is set to the WikiWord."
(file-exists-p (match-string 1 string))))
(match-string 1 string)))

;; Pretty title
;; Prettifications

(defcustom muse-wiki-publish-small-title-words
'("the" "and" "at" "on" "of" "for" "in" "an" "a")
Expand All @@ -178,25 +195,39 @@ called manually."
:type '(repeat string)
:group 'muse-wiki)

(defun muse-wiki-publish-pretty-title (&optional title)
"Return a pretty version of the given TITLE."
(defun muse-wiki-publish-pretty-title (&optional title explicit)
"Return a pretty version of the given TITLE.
If EXPLICIT is non-nil, TITLE will be returned unmodified."
(unless title (setq title (muse-publishing-directive "title")))
(save-match-data
(let ((case-fold-search nil))
(while (string-match (concat "\\([" muse-regexp-upper
muse-regexp-lower
"]\\)\\([" muse-regexp-upper
"0-9]\\)")
title)
(setq title (replace-match "\\1 \\2" t nil title)))
(let* ((words (split-string title))
(w (cdr words)))
(while w
(if (member (downcase (car w))
muse-wiki-publish-small-title-words)
(setcar w (downcase (car w))))
(setq w (cdr w)))
(mapconcat 'identity words " ")))))
(if (or explicit
(save-match-data (string-match muse-url-regexp title)))
title
(save-match-data
(let ((case-fold-search nil))
(while (string-match (concat "\\([" muse-regexp-upper
muse-regexp-lower
"]\\)\\([" muse-regexp-upper
"0-9]\\)")
title)
(setq title (replace-match "\\1 \\2" t nil title)))
(let* ((words (split-string title))
(w (cdr words)))
(while w
(if (member (downcase (car w))
muse-wiki-publish-small-title-words)
(setcar w (downcase (car w))))
(setq w (cdr w)))
(mapconcat 'identity words " "))))))

(defun muse-wiki-publish-pretty-interwiki (desc &optional explicit)
"Replace instances of `muse-wiki-interwiki-delimiter' with
`muse-wiki-interwiki-replacement'."
(if (or explicit
(save-match-data (string-match muse-url-regexp desc)))
desc
(muse-replace-regexp-in-string muse-wiki-interwiki-delimiter
muse-wiki-interwiki-replacement
desc)))

;; Coloring setup

Expand Down Expand Up @@ -228,7 +259,12 @@ called manually."
t)
(add-to-list 'muse-publish-markup-regexps
'(3200 muse-wiki-wikiword-regexp 0 link)
t)))
t)

(custom-add-option 'muse-publish-desc-transforms
'muse-wiki-publish-pretty-interwiki)
(custom-add-option 'muse-publish-desc-transforms
'muse-wiki-publish-pretty-title)))

;; Insinuate link handling

Expand Down
35 changes: 19 additions & 16 deletions lisp/muse.el
Expand Up @@ -70,27 +70,30 @@ familiar with Emacs."
"A regexp of extensions to omit from the ending of a Muse page name.
This is autogenerated from `muse-ignored-extensions'.")

(defun muse-update-file-extension (sym val)
"Update the value of `muse-file-extension'."
(when (and (boundp sym) (symbol-value sym))
;; remove old auto-mode-alist association
(setq auto-mode-alist
(delete (cons (concat "\\." (symbol-value sym) "\\'")
'muse-mode-choose-mode)
auto-mode-alist)))
(set sym val)
;; associate .muse with muse-mode
(when val
(add-to-list 'auto-mode-alist
(cons (concat "\\." val "\\'")
'muse-mode-choose-mode)))
(when (fboundp 'muse-update-ignored-extensions-regexp)
(muse-update-ignored-extensions-regexp
'muse-ignored-extensions muse-ignored-extensions)))

(defcustom muse-file-extension nil
"File extension of Muse files. Omit the period at the beginning."
:type '(choice
(const :tag "None" nil)
(string))
:set #'(lambda (sym val)
(when (and (boundp sym) (symbol-value sym))
;; remove old auto-mode-alist association
(setq auto-mode-alist
(delete (cons (concat "\\." (symbol-value sym) "\\'")
'muse-mode-choose-mode)
auto-mode-alist)))
(set sym val)
;; associate .muse with muse-mode
(when val
(add-to-list 'auto-mode-alist
(cons (concat "\\." val "\\'")
'muse-mode-choose-mode)))
(when (fboundp 'muse-update-ignored-extensions-regexp)
(muse-update-ignored-extensions-regexp
'muse-ignored-extensions muse-ignored-extensions)))
:set 'muse-update-file-extension
:group 'muse)

(defun muse-update-ignored-extensions-regexp (sym val)
Expand Down

0 comments on commit 7ffe752

Please sign in to comment.