diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2006-07-28 06:44:34 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2006-07-28 06:44:34 +0000 |
commit | eba3215f2561b148fe0aab30fa9ceb5f09f40eae (patch) | |
tree | 4a75004b3620c3a50d65ae77f20c96292f4cf1d0 /elisp | |
parent | fd2bf07ed20fe94af6093b1aebaa3448c9ee6d86 (diff) | |
download | gsc-eba3215f2561b148fe0aab30fa9ceb5f09f40eae.tar.gz gsc-eba3215f2561b148fe0aab30fa9ceb5f09f40eae.tar.bz2 |
Change node structure: add anchor field.
All references updated.
(get-token): Optional [word] after leading asterisks sets
anchor name for referencing the entry from outside.
(scan-reference,scan-text): Support anchors.
git-svn-id: file:///svnroot/gsc/trunk@208 d2de0444-eb31-0410-8365-af798a554d48
Diffstat (limited to 'elisp')
-rw-r--r-- | elisp/links-mode.el | 55 |
1 files changed, 35 insertions, 20 deletions
diff --git a/elisp/links-mode.el b/elisp/links-mode.el index c534037..61ff803 100644 --- a/elisp/links-mode.el +++ b/elisp/links-mode.el @@ -1,11 +1,11 @@ ;;; links-mode.el --- major mode for editing bookmark files -;; Authors: 2005 Sergey Poznyakoff +;; Authors: 2005, 2006 Sergey Poznyakoff ;; Version: 1.0 ;; Keywords: links,bookmarks,html ;; $Id$ -;; Copyright (C) 2005 Sergey Poznyakoff +;; Copyright (C) 2005, 2006 Sergey Poznyakoff ;; 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 @@ -23,16 +23,17 @@ ;; Tree node structure: ;; -;; (vector title ref text subtree toc) +;; (vector title ref anchor text subtree toc) ;; ;; title string ;; ref nil or string +;; anchor nil or string ;; text list of string ;; subtree list of nodes ;; tok nil or number -(defmacro node-create (title ref) - (` (vector (, title) (, ref) nil nil nil))) +(defmacro node-create (title ref anchor) + (` (vector (, title) (, ref) (, anchor) nil nil nil))) (defmacro node-title (n) (` (aref (, n) 0))) @@ -46,29 +47,32 @@ (defmacro node-set-ref (n val) (` (aset (, n) 1 (, val)))) -(defmacro node-text (n) +(defmacro node-anchor (n) (` (aref (, n) 2))) +(defmacro node-text (n) + (` (aref (, n) 3))) + (defmacro node-set-text (n val) - (` (aset (, n) 2 (, val)))) + (` (aset (, n) 3 (, val)))) (defmacro node-add-text (n val) (` (node-set-text (, n) (append (node-text (, n)) (list (, val)))))) (defmacro node-subtree (n) - (` (aref (, n) 3))) + (` (aref (, n) 4))) (defmacro node-set-subtree (n val) - (` (aset (, n) 3 (, val)))) + (` (aset (, n) 4 (, val)))) (defmacro node-add-subtree (n val) (` (node-set-subtree (, n) (append (node-subtree (, n)) (list (, val)))))) (defmacro node-toc (n) - (` (aref (, n) 4))) + (` (aref (, n) 5))) (defmacro node-set-toc (n val) - (` (aset (, n) 4 (, val)))) + (` (aset (, n) 5 (, val)))) @@ -77,16 +81,23 @@ the token ('reference, 'newline or 'text). Rest of list elements depend on the token type: - (list 'reference level title [ref]) + (list 'reference level title [ref] [name]) (list 'text string) (list 'newline) " (cond - ((looking-at "^\\(\\*+\\)[ \t]*\\(.*\\)[ \t]*::[ \t]*\\(.*\\)$") - (list 'reference (length (match-string 1)) - (match-string 3) (match-string 2))) - ((looking-at "^\\(\\*+\\)[ \t]*\\(.*\\)$") - (list 'reference (length (match-string 1)) (match-string 2))) + ((looking-at "^\\(\\*+\\)[ \t]*\\(\\[\\([^]]+\\)\\]\\)?[ \t]*\\(.*\\)[ \t]*::[ \t]*\\(.*\\)$") + (list 'reference + (length (match-string 1)) + (match-string 5) + (match-string 4) + (match-string 3))) + ((looking-at "^\\(\\*+\\)[ \t]*\\(\\[\\([^]]+\\)\\]\\)?[ \t]*\\(.*\\)$") + (list 'reference + (length (match-string 1)) + (match-string 4) + nil + (match-string 3))) ((or (looking-at "^[ \t]*$") (looking-at "^[ \t]*;.*$")) (list 'newline)) (t @@ -99,14 +110,15 @@ the token type: "Scan a reference" (let ((level (nth 1 tok)) (title (list (nth 2 tok))) - (ref (and (= (length tok) 4) (nth 3 tok)))) + (ref (nth 3 tok)) + (anchor (nth 4 tok))) (while (and (not (eobp)) (eq (car (setq tok (get-token))) 'text)) (setq title (cons (cadr tok) (cons " " title))) (forward-line)) (let ((tree (cons - (node-create (apply 'concat (nreverse title)) ref) + (node-create (apply 'concat (nreverse title)) ref anchor) root))) (while (and (not (eobp)) (eq (car (setq tok (get-token))) 'newline)) @@ -129,7 +141,7 @@ the token type: (defun scan-text (root tok) "Scan a paragraph of text" - (let ((tree (or root (list (node-create nil nil)))) + (let ((tree (or root (list (node-create nil nil nil)))) para) (while (and (not (eobp)) (eq (car (setq tok (get-token))) 'text)) (setq para (cons (cadr tok) (cons "\n" para))) @@ -193,9 +205,12 @@ the token type: (defun out-tree (tree) (mapc (function (lambda (node) (let ((ref (node-ref node)) + (anchor (node-anchor node)) (text (node-text node)) (subtree (node-subtree node))) (insert "<li>") + (when anchor + (insert "<a name=\"" anchor "\"></a>")) (cond (ref (insert "<a href=\"" ref "\">" |