emacs-wiki-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[emacs-wiki-discuss] Some more protocols


From: Phillip Lord
Subject: [emacs-wiki-discuss] Some more protocols
Date: Wed, 8 Mar 2006 13:27:38 -0000




Thought I would send in the following code which implements additional
protocol handlers. One is for DOI's (digitial object identifiers)
which are becoming a standards identifier in the publising industry. 
I'm not 100% sure, but I think that the proxy server used in resolve
should work for all DOI's. And secondly an interwiki link -- I know
about
the link in muse-wiki, but I wanted something that worked all the time. 
I have a few wiki's in my home space, and in many cases their website
layout
and location in my file space are not the same. This allows links
between 
them using an "url" looking like "iw:home/emacs". 


Incidentally, has anyone else had strange problems with protocols 
when running emacs in batch? I've found that when changing
muse-url-protocols
in a normal, interactive, emacs muse-url-regexp gets updated correctly 
(even though I don't use custom to do this). But in batch, it doesn't
update. 

I was going to suggest deleting muse-url-regexp and replacing it with a
function for use instead (of course, there is nothing to stop the
function
from storing the regexp it calculates, and then checking each time to
make
sure that muse-url-protocols hasn't changed). This way, muse would not
be
relying on a side-effect of custom setting muse-url-protocol to keep
things 
up to date. 


;; COPYRIGHT NOTICE
;;
;; This program 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 2, or (at your option)
;; any later version.

;; This program 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 this program; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA. 

     ;; additional protocol handling. 
     ;; doi "url" handling
     (add-to-list 'muse-url-protocols
                  '("doi:" phil-muse-browse-url-doi
phil-muse-resolve-url-doi))
     
     
     (defun phil-muse-resolve-url-doi (url)
       "Return the URL through doi proxy server"
       (when (string-match "\\`doi:\\(.+\\)" url)
         (concat "http://dx.doi.org/";
                 (match-string 1 url))))
     
     
     (defun phil-muse-browse-url-doi (url)
       (let ((doi-url (phil-muse-resolve-url-doi url)))
         (when doi-url
           (browse-url doi-url))))
     
     ;; interwiki protocol handling. This enables non wiki word type
     ;; interwiki support, with a different local resolve. 
     ;; (adelete 'muse-url-protocols "iw:")
     (add-to-list 'muse-url-protocols
                  '("iw:" phil-muse-browse-url-iw
phil-muse-resolve-url-iw))

     (setq phil-muse-interwiki-protocol-alist
           '(("home" "/" "~/src/ht/home_website")))
           
     
     (defun phil-muse-resolve-url-iw (url)
       (when (string-match "\\`iw:\\([a-zA-Z]*\\)\\\\\\(.+\\)" url)
         (let* ((wiki-resolve 
                 (assoc (match-string 1 url)
                        phil-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 phil-muse-browse-url-iw (url)
       (when (string-match "\\`iw:\\([a-zA-Z]*\\)\\\\\\(.+\\)#\\(.+\\)"
url)
         (let* ((wiki-resolve 
                 (assoc (match-string 1 url)
                        phil-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")))))
     






reply via email to

[Prev in Thread] Current Thread [Next in Thread]