📄 docbookide.el
字号:
;;;; docbookide.el --- DocBook Integrated Development Environment
;; $Id: docbookide.el,v 1.1.1.1 2000/03/29 18:57:00 nwalsh Exp $
;; Copyright (C) 2000 Norman Walsh
;; Based extensively on (one might go so far as to say "totally hacked
;; from") Tony Graham's xslide.
;; Author: Norman Walsh <ndw@nwalsh.com>
;; Created: 29 March 2000
;; Version: $Revision: 1.1.1.1 $
;; Keywords: languages, xml, docbook
;;; This file is not part of GNU Emacs.
;; 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
;; of the License, 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., 675 Mass Ave, Cambridge, MA 02139, USA.
;;;; Commentary:
;; Functions for editing DocBook documents
;; Requires dbide-font.el
;; Requires 'etags for `find-tag-default'
;; Requires 'reporter for `docbook-submit-bug-report'
;;
;; Send bugs to docbookide-bug@nwalsh.com
;; Use `docbook-submit-bug-report' for bug reports
;;;; Code:
(provide 'docbookide)
(require 'cl)
(require 'compile)
(require 'font-lock)
;; We need etags for `find-tag-default'
(require 'etags)
(require 'dbide-data "dbide-data")
(require 'dbide-abbrev "dbide-abbrev")
(require 'dbide-font "dbide-font")
(require 'dbide-process "dbide-process")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Version information
(defconst docbookide-version "0.1"
"Version number of docbookide.")
(defun docbookide-version ()
"Returns the value of the variable docbookide-version."
docbookide-version)
(defconst docbookide-maintainer-address "docbookide-bug@nwalsh.com")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Variables
(defvar docbook-default-filespec "*.xml"
"*Inital prompt value for `docbook-etags''s FILESPEC argument.")
(defvar docbook-filespec-history (list docbook-default-filespec)
"Minibuffer history list for `docbook-etags' and `docbook-grep''s FILESPEC argument.")
(defvar docbook-grep-pattern-history nil
"Minibuffer history list for `docbook-grep''s PATTERN argument.")
(defvar docbook-grep-case-sensitive-flag nil
"*Non-nil disables case insensitive searches by `docbook-grep'.")
(defvar docbook-comment-start "<!--"
"*Comment start character sequence")
(defvar docbook-comment-end "-->"
"*Comment end character sequence")
(defvar docbook-comment-max-column 70
"*Maximum column number for text in a comment")
;; DOCBOOKIDE house style puts all comments starting on a favourite column
(defun docbook-comment (comment)
"Insert COMMENT starting at the usual column.
With a prefix argument, e.g. \\[universal-argument] \\[docbook-comment], insert separator comment
lines above and below COMMENT in the manner of `docbook-big-comment'."
(interactive "sComment: ")
(insert "\n")
(backward-char)
(let ((fill-column (1- docbook-comment-max-column))
(fill-prefix (make-string (1+ (length docbook-comment-start)) ?\ ))
;; (comment-start docbook-init-comment-fill-prefix)
(saved-auto-fill-function auto-fill-function))
(auto-fill-mode 1)
(insert docbook-comment-start)
(indent-to (length fill-prefix))
(fill-region (point) (save-excursion
(insert comment)
(point))
nil
1
1)
;; The fill does the right thing, but it always ends with
;; an extra newline, so we delete the newline.
(delete-backward-char 1)
(if (not saved-auto-fill-function)
(auto-fill-mode 0))
(insert " ")
(insert docbook-comment-end)
(insert "\n")
(if font-lock-mode
(save-excursion
(font-lock-fontify-keywords-region
(docbook-font-lock-region-point-min)
(docbook-font-lock-region-point-max))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Mode map stuff
(defvar docbook-mode-map nil
"Keymap for DOCBOOK mode.")
(defvar docbook-context-tab nil
"Toggle automatic tabbing behavior.")
(if docbook-mode-map
()
(setq docbook-mode-map (make-sparse-keymap))
(define-key docbook-mode-map [(control c) tab] 'docbook-force-electric-tab)
(define-key docbook-mode-map [tab] 'docbook-complete)
(define-key docbook-mode-map "\"" 'docbook-electric-quote)
(define-key docbook-mode-map "'" 'docbook-electric-apos)
(define-key docbook-mode-map "/" 'docbook-electric-slash)
(define-key docbook-mode-map "<" 'docbook-electric-less-than)
(define-key docbook-mode-map "[" 'docbook-electric-lsqb)
(define-key docbook-mode-map "(" 'docbook-electric-lpar)
(define-key docbook-mode-map "{" 'docbook-electric-lcub)
(define-key docbook-mode-map [(control c) (control p)]
'docbook-process)
(define-key docbook-mode-map "\C-c<" 'docbook-insert-tag)
(define-key docbook-mode-map "\177" 'backward-delete-char-untabify)
)
(defun docbook-electric-apos ()
"Function called when \"'\" is pressed in DOCBOOK mode"
(interactive)
(insert "'")
(if (looking-at "\\([\"/})]\\|$\\)")
(save-excursion
(insert "'"))))
(defun docbook-electric-quote ()
"Function called when '\"' is pressed in DOCBOOK mode"
(interactive)
(insert "\"")
(if (looking-at "\\(['/})]\\|$\\)")
(save-excursion
(insert "\""))))
(defun docbook-electric-lsqb ()
"Function called when \"[\" is pressed in DOCBOOK mode"
(interactive)
(insert "[")
(if (looking-at "\\([\"'/})]\\|$\\)")
(save-excursion
(insert "]"))))
(defun docbook-electric-lpar ()
"Function called when \"(\" is pressed in DOCBOOK mode"
(interactive)
(insert "(")
(if (looking-at "\\([\]\"'/}]\\|$\\)")
(save-excursion
(insert ")"))))
(defun docbook-electric-lcub ()
"Function called when \"{\" is pressed in DOCBOOK mode"
(interactive)
(insert "{")
(if (looking-at "\\([\])\"'/}]\\|$\\)")
(save-excursion
(insert "}"))))
(defun docbook-electric-less-than ()
"Function called when \"<\" is pressed in DOCBOOK mode"
(interactive)
(insert "<")
(docbook-electric-tab))
(defun docbook-electric-slash ()
"Function called when \"/\" is pressed in DOCBOOK mode"
(interactive)
(insert "/")
(docbook-electric-tab)
(if (looking-at "$")
(let ((element-name
(save-excursion
(backward-char 2)
(if (looking-at "</")
(catch 'start-tag
(while (re-search-backward "<" nil t)
(cond
((looking-at "</\\([^/> \t]+\\)>")
;; (message "End tag: %s" (match-string 1))
(re-search-backward
(concat "<" (match-string 1) "[ \t\n\r>]") nil t))
((looking-at "<\\(\\([^/>]\\|/[^>]\\)+\\)/>"))
;; (message "Empty tag: %s" (match-string 1)))
((looking-at "<!--[^-]*\\(-[^-]+\\)*-->"))
((looking-at "<\\([^/> \t]+\\)")
;; (message "Start tag: %s" (match-string 1))
(throw 'start-tag (match-string 1)))
((bobp)
(throw 'start-tag nil)))))
nil))))
(if element-name
(insert (concat element-name ">"))))))
(defun docbook-electric-return ()
(interactive)
(insert "\n")
(docbook-electric-tab))
(defun docbook-electric-tab ()
(interactive)
(if docbook-context-tab
(docbook-force-electric-tab)))
(defun docbook-force-electric-tab ()
"Function called when TAB is pressed in DOCBOOK mode."
(interactive)
(save-excursion
(beginning-of-line)
(delete-horizontal-space)
(if (looking-at "</")
(indent-to (max 0 (- (docbook-calculate-indent) 2)))
(indent-to (docbook-calculate-indent))))
(if (and
(bolp)
(looking-at "[ \t]+"))
(goto-char (match-end 0))))
(defun docbook-calculate-indent ()
"Calculate what the indent should be for the current line"
(interactive)
(save-excursion
(if (re-search-backward "^\\([ \t]*\\)<" nil t)
(goto-char (match-end 1))
(beginning-of-line))
(if (or
(save-excursion
(re-search-forward "\\(</[^<>]+>\\|<[^/][^<>]+/>\\)[ \t]*$"
(save-excursion (end-of-line) (1+ (point)))
t))
(bobp))
(current-column)
(+ (current-column) 2))))
(defun docbook-complete ()
"Complete the tag or attribute before point.
If it is a tag (starts with < or </) complete with allowed tags,
otherwise complete with allowed attributes."
(interactive "*")
(let ((tab ; The completion table
nil)
(pattern nil)
(c nil)
(here (point))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -