;;; link.el -- putting clickable links into the buffer;; Author: Torsten Hilbrich <dictionary@myrkr.in-berlin.de>;; Keywords: interface, hypermedia;; $Id$;; This file 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 file 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 GNU Emacs; see the file COPYING. If not, write to;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,;; Boston, MA 02111-1307, USA.;; Commentary:;; This file contains functions for using links in buffers. A link is;; a part of the buffer marked with a special face, beeing;; hightlighted while the mouse points to it and beeing activated when;; pressing return or clicking the button2.;; Which each link a function and some data are associated. Upon;; clicking the function is called with the data as only argument.(eval-when-compile(require'cl))(defunlink-create-link(startendfacefunction&optionaldatahelp)"Create a link in the current buffer starting from `start' going to `end'.The `face' is used for displaying, the `data' are stored together with thelink. Upon clicking the `function' is called with `data' as argument."(let((properties`(face,facemouse-facehighlightlinktlink-data,datahelp-echo,helplink-function,function)))(remove-text-propertiesstartendproperties)(add-text-propertiesstartendproperties)))(defunlink-insert-link(textfacefunction&optionaldatahelp)"Insert the `text' at point to be formatted as link.The `face' is used for displaying, the `data' are stored together with thelink. Upon clicking the `function' is called with `data' as argument."(let((start(point)))(inserttext)(link-create-linkstart(point)facefunctiondatahelp)))(defunlink-selected(&optionalall)"Is called upon clicking or otherwise visiting the link."(interactive)(let*((properties(text-properties-at(point)))(function(plist-getproperties'link-function))(data(plist-getproperties'link-data)))(iffunction(funcallfunctiondataall))))(defunlink-selected-all()"Called for meta clicking the link"(interactive)(link-selected'all))(defunlink-mouse-click(event&optionalall)"Is called upon clicking the link."(interactive"@e")(mouse-set-pointevent)(link-selected))(defunlink-mouse-click-all(event)"Is called upon meta clicking the link."(interactive"@e")(mouse-set-pointevent)(link-selected-all))(defunlink-next-link()"Return the position of the next link or nil if there is none"(let*((pos(point))(pos(next-single-property-changepos'link)))(ifpos(if(text-property-anypos(min(1+pos)(point-max))'linkt)pos(next-single-property-changepos'link))nil)))(defunlink-prev-link()"Return the position of the previous link or nil if there is none"(let*((pos(point))(pos(previous-single-property-changepos'link)))(ifpos(if(text-property-anypos(1+pos)'linkt)pos(let((val(previous-single-property-changepos'link)))(ifvalval(text-property-any(point-min)(1+(point-min))'linkt))))nil)))(defunlink-initialize-keymap(keymap)"Defines the necessary bindings inside keymap"(if(and(boundp'running-xemacs)running-xemacs)(progn(define-keykeymap[button2]'link-mouse-click)(define-keykeymap[(metabutton2)]'link-mouse-click-all))(define-keykeymap[mouse-2]'link-mouse-click)(define-keykeymap[M-mouse-2]'link-mouse-click-all))(define-keykeymap"\r"'link-selected)(define-keykeymap"\M-\r"'link-selected-all))(provide'link)