File: muse-protocol-iw.el

package info (click to toggle)
muse-el 3.12-1.1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 1,688 kB
  • ctags: 905
  • sloc: lisp: 11,772; makefile: 304; python: 106; sh: 51; perl: 46
file content (70 lines) | stat: -rw-r--r-- 2,570 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
;;; muse-protocol-iw.el --- implement an interwiki protocol handler

;; Copyright (C) 2006 Free Software Foundation, Inc.

;; Author: Phillip Lord <phillip.lord@newcastle.ac.uk>

;; This file is part of Emacs Muse.  It is not part of GNU Emacs.

;; Emacs Muse is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published
;; by the Free Software Foundation; either version 3, or (at your
;; option) any later version.

;; Emacs Muse is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;; General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with Emacs Muse; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.

;;; Commentary:

;; This defines a new url type, which is like the interwiki support of
;; muse-wiki. You can also publish to a different directory structure
;; from the file space (which I do for historical reasons). So a link
;; like

;; [[iw:home\emacs][hello]] will work from any of the individual muse
;; projects that I have.

(require 'muse-protocols)

(add-to-list 'muse-url-protocols
             '("iw:" muse-browse-url-iw muse-resolve-url-iw))

(defvar muse-interwiki-protocol-alist
      '(("home" "/" "~/src/ht/home_website")
        ("silly" "/silly/" "~/src/ht/home_website/silly")
        ("energy" "/energy/" "~/src/ht/home_website/energy")
        ("journal" "/journal/" "~/src/ht/home_website/journal")))

(defun muse-resolve-url-iw (url)
  (when (string-match "\\`iw:\\([a-zA-Z]*\\)\\\\\\(.+\\)" url)
    (let* ((wiki-resolve
            (assoc (match-string 1 url)
                   muse-interwiki-protocol-alist))
           (publish-resolve
            (nth 1 wiki-resolve)))
      (concat publish-resolve (match-string 2 url)))))

;; this doesn't handle anchors properly yet.
(defun muse-browse-url-iw (url)
  (when (string-match "\\`iw:\\([a-zA-Z]*\\)\\\\\\(.+\\)#?\\(.*\\)" url)
    (let* ((wiki-resolve
            (assoc (match-string 1 url)
                   muse-interwiki-protocol-alist))
           (browse-resolve
            (or (nth 2 wiki-resolve)
                (nth 1 wiki-resolve))))
      (find-file
       (concat browse-resolve "/"
               (match-string 2 url)
               ".muse")))))


(provide 'muse-protocol-iw)
;; muse-protocol-iw.el ends here