;;; klink.el --- Implicit reference to a kcell action type, for use in koutlines. ;; Copyright (C) 1993, 1995 Free Software Foundation, Inc. ;; Developed with support from Motorola Inc. ;; Author: Bob Weiner, Brown U. ;; Kellie Clark ;; Maintainer: Mats Lidell ;; Keywords: extensions, hypermedia, outlines, wp ;; This file is part of GNU Hyperbole. ;; GNU Hyperbole 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. ;; GNU Hyperbole 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., 51 Franklin Street, Fifth Floor, ;; Boston, MA 02110-1301, USA. ;;; Commentary: ;; ;;; link = ;; < pathname [, cell-ref] [, position] > ;; < @ cell-ref > ;; In same buffer ;; < journal-name, journal-item-number [, cell-ref] [, position] > ;; ;;; pathname = ;; path ;; display path in Emacs buffer ;; !path ;; execute pathname within a shell ;; &path ;; execute path as a windowed program ;; -path ;; Load as an Emacs Lisp program ;; ;;; cell-ref = ;; cell - 1a, 012, 1.2, 1a=012 (both relative and absolute ids separated ;; by an equal sign) ;; range - 1a-5c, 1a-+3 (include 3 cells past 1a) (not yet implemented) ;; tree - 1a+ (not yet implemented) ;; ;; optionally followed by a period and 1 or more relative position specs ;; (not yet implemented): ;; ;; previous-cell - .b ;; down-a-level - .d ;; end-of-branch - .e ;; follow-next-link - .l ;; return-to-prev-location - .r ;; return-to-prev-buffer - .rf ;; sibling - .s, .2s for 2 siblings forward ;; tail-of-tree - .t ;; up-a-level - .u ;; last char of cell - .f ;; ;; and then optionally followed by any amount of whitespace, a pipe `|' ;; character and then one or more view specification characters. (Augment ;; viewspec characters may be given instead, preceded by a colon. They are ;; ignored for now.) ;; ;;; position (relative to cell start) = (not yet implemented) ;; char-pos, e.g. 28 or C28 ;; word-num, e.g. W5 ;; line-num, e.g. L2 ;; paragraph-num, e.g. P3 ;; regexp-match, e.g. "regexp" ;; ;;; Code: ;;; ;;; Public functions ;;; ;;;###autoload (defun klink:create (reference) "Insert at point an implicit link to REFERENCE. REFERENCE should be a cell-ref or a string containing \"filename, cell-ref\". See documentation for 'kcell:ref-to-id' for valid cell-ref formats." (interactive ;; Don't change the name or delete default-dir used here. It is referenced ;; in "hargs.el" for argument getting. (let ((default-dir default-directory)) (barf-if-buffer-read-only) (hargs:iform-read (list 'interactive "*+LInsert link to <[file,] cell-id [|vspecs]>: ")))) (barf-if-buffer-read-only) ;; Reference generally is a string. It may be a list as a string, e.g. ;; "(\"file\" \"cell\")", in which case, we remove the unneeded internal ;; double quotes and then parse it with pattern matching. (and (stringp reference) (> (length reference) 0) (= (aref reference 0) ?\() (setq reference (hypb:replace-match-string "\\\"" reference "" t))) (let ((default-dir default-directory) file-ref cell-ref) (setq reference (klink:parse reference) file-ref (car reference) cell-ref (car (cdr reference))) ;; Don't need filename if link is to a cell in current buffer. (if (and file-ref (equal buffer-file-name (expand-file-name file-ref default-directory))) (setq file-ref nil)) (cond (file-ref (setq file-ref (hpath:relative-to file-ref)) ;; "./" prefix, if any. (if (string-match "^\\./" file-ref) (setq file-ref (substring file-ref (match-end 0)))) (insert "<" file-ref) (if cell-ref (insert ", " cell-ref)) (insert ">")) (cell-ref (insert "<@ " cell-ref ">")) (t (error "(klink:create) Invalid reference, '%s'" reference))))) (defun klink:at-p () "Return non-nil iff point is within a klink. See documentation for the `link-to-kotl' function for valid klink formats. Value returned is a list of: link-label, link-start-position, and link-end-position, (including delimiters)." (let (bol klink referent) (if (and ;; If this is an OO-Browser listing buffer, ignore anything that ;; looks like a klink, e.g. a C++