aboutsummaryrefslogtreecommitdiff
path: root/elisp
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2005-07-04 06:33:02 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2005-07-04 06:33:02 +0000
commit1dc1e63cdd34d384769f663d454b83584ac0b1f6 (patch)
tree972f9e14d7cba2dd10a801fe4b874918f270f2f1 /elisp
parentc64ac3cf2db58aa01236a4dd3efb87be2a5e39da (diff)
downloadgsc-1dc1e63cdd34d384769f663d454b83584ac0b1f6.tar.gz
gsc-1dc1e63cdd34d384769f663d454b83584ac0b1f6.tar.bz2
Added to the repository
git-svn-id: file:///svnroot/gsc/trunk@49 d2de0444-eb31-0410-8365-af798a554d48
Diffstat (limited to 'elisp')
-rw-r--r--elisp/links-mode.el169
1 files changed, 169 insertions, 0 deletions
diff --git a/elisp/links-mode.el b/elisp/links-mode.el
new file mode 100644
index 0000000..a8620b5
--- /dev/null
+++ b/elisp/links-mode.el
@@ -0,0 +1,169 @@
+;;; links-mode.el --- major mode for editing bookmark files
+
+;; Authors: 2005 Sergey Poznyakoff
+;; Version: 1.0
+;; Keywords: links,bookmarks,html
+;; $Id$
+
+;; Copyright (C) 2005 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
+;; 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; if not, write to the Free Software Foundation,
+;; Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+(defun link-paragraph-begin ()
+ (save-excursion
+ (set-buffer link-output-buffer)
+ (insert "\n<p>\n")))
+
+(defun link-paragraph-end ()
+ (save-excursion
+ (set-buffer link-output-buffer)
+ (insert "\n</p>\n")))
+
+(defun link-paragraph-line (text)
+ (save-excursion
+ (set-buffer link-output-buffer)
+ (insert text "\n")))
+
+(defun link-node-begin (level)
+ (save-excursion
+ (set-buffer link-output-buffer)
+ (insert "<ul>\n")))
+
+(defun link-node-end (level)
+ (save-excursion
+ (set-buffer link-output-buffer)
+ (insert "</ul>\n")))
+
+(defun link-reference-begin (level title &optional ref)
+ (save-excursion
+ (set-buffer link-output-buffer)
+ (insert "<li>")
+ (if ref
+ (insert "<a href=\"" ref "\">" title "</a>\n")
+ (insert "<h3>" title "</h3>"))))
+
+(defun link-reference-end (level)
+ (save-excursion
+ (set-buffer link-output-buffer)
+ (insert "</li>\n")))
+
+
+
+(defun get-token ()
+ (cond
+ ((looking-at "^\\(\\*+\\)\\s *\\(.*\\)\\s *::\\s *\\(.*\\)$")
+ (list 'reference (length (match-string 1)) (match-string 3) (match-string 2)))
+ ((looking-at "^\\(\\*+\\)\\s *\\(.*\\)$")
+ (list 'reference (length (match-string 1)) (match-string 2)))
+ ((or (looking-at "^\\s *$") (looking-at "^\\s *;.*$"))
+ (list 'newline))
+ (t
+ (list 'text (save-excursion (let ((here (point)))
+ (buffer-substring here (progn
+ (forward-line)
+ (point)))))))))
+
+
+(defun scan-reference (tok)
+ (let ((level (nth 1 tok))
+ (title (list (nth 2 tok)))
+ (ref (and (= (length tok) 4) (nth 3 tok))))
+
+ (while (and (not (eobp)) (eq (car (setq tok (get-token))) 'text))
+ (setq title (cons (cadr tok) (cons " " title)))
+ (forward-line))
+
+ (link-reference-begin level (apply 'concat (nreverse title)) ref)
+
+ (while (and (not (eobp)) (eq (car (setq tok (get-token))) 'newline))
+ (forward-line))
+
+ (when (and (not (eobp))
+ (eq (car tok) 'text))
+ (scan-buffer (1+ level))
+ (while (and (not (eobp)) (eq (car (setq tok (get-token))) 'newline))
+ (forward-line)))
+
+ (when (and
+ (not (eobp))
+ (eq (car tok) 'reference)
+ (> (nth 1 tok) level))
+ (let ((lev (nth 1 tok)))
+ (link-node-begin lev)
+ (scan-buffer lev)
+ (link-node-end lev)))
+
+ (link-reference-end level)))
+
+
+(defun scan-text (tok)
+ (link-paragraph-begin)
+ (link-paragraph-line (cadr tok))
+ (while (and (not (eobp)) (eq (car (setq tok (get-token))) 'text))
+ (link-paragraph-line (cadr tok))
+ (forward-line))
+ (link-paragraph-end))
+
+(defun scan-buffer (level)
+ (let (tok)
+ (while (and (not (eobp))
+ (or (not (eq (car (setq tok (get-token))) 'reference))
+ (= (nth 1 tok) level)))
+ (let ((tok-type (car tok)))
+ (forward-line)
+ (cond
+ ((eq tok-type 'reference)
+ (scan-reference tok))
+ ((eq tok-type 'text)
+ (scan-text tok)))))))
+
+(defun scan-links (&optional buffer-name)
+ (interactive "p")
+ (save-excursion
+ (beginning-of-buffer)
+ (let ((link-output-buffer (get-buffer-create
+ (or buffer-name links-output-file)))
+ (template links-template-file))
+ (save-excursion
+ (set-buffer link-output-buffer)
+ (erase-buffer)
+ (when template
+ (insert-file template)
+ (beginning-of-buffer)
+ (unless (search-forward "$$" nil t)
+ (error "Template file without $$"))
+ (delete-region (point) (- (point) 2))))
+ (scan-buffer 1))))
+
+
+
+(defun links-compile (arg)
+ (interactive "p")
+ (scan-links))
+
+;;;###autoload
+(define-derived-mode links-mode outline-mode "Links"
+ "Major mode for editing link (bookmark) pages. It is much like Outline.
+
+ Key bindings:
+\\{links-mode-map}"
+
+ (set (make-variable-buffer-local 'links-output-file) "links.html")
+ (set (make-variable-buffer-local 'links-template-file) "links.tmpl")
+ (define-key links-mode-map "\C-c\C-c" 'links-compile))
+
+(provide 'links-mode)
+
+;;; links-mode.el ends

Return to:

Send suggestions and report system problems to the System administrator.