⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 docbookide.el

📁 docbookide 一个docbook插件
💻 EL
📖 第 1 页 / 共 2 页
字号:
	(prev-oab (point))
	(prev-cab (point))
	(start-tag nil))
    (setq prev-oab (search-backward "<" nil t nil))
    (if (looking-at "<\\([^/> \t]+\\)")
	(setq start-tag (match-string 1)))
    (goto-char here) ;; move back from where the searches moved us...
    (setq prev-cab (search-backward ">" nil t nil))
    (goto-char here) ;; move back from where the searches moved us...
    (skip-chars-backward "^ \n\t</!&%")
    (setq pattern (buffer-substring (point) here))
    (setq c (char-after (1- (point))))
;    (message (format "c = %s (%s)" c start-tag))
;    (message (format "oab: %d cab: %d" prev-oab prev-cab))
;    (if (and (eq c ? ) (> prev-oab prev-cab))
;	(message "and is true")
;      (message "and is false"))
    (cond
     ;; start-tag
     ((eq c ?<)
      (setq tab docbook-all-elements-alist))
     ;; attribute (we're only on an attribute if the thing before this
     ;; word is a space and we're inside < and >. Then only let the
     ;; attributes allowed on a given element to be possible completions.
     ;; If we can't figure out what's allowed, let all the attributes
     ;; be the completion.
     ((and (eq c ? ) (> prev-oab prev-cab))
      (if start-tag
	  (let* ((eleminfo (assoc start-tag docbook-all-elements-alist))
		 (attrs    (if eleminfo
			       (nth 2 eleminfo)
			     nil)))
	    (if attrs
		(setq tab (mapcar (lambda (x)
				    (list x x nil))
				  attrs))
	      (setq tab docbook-all-attribute-alist)))
	(setq tab docbook-all-attribute-alist)))
     (t
      (goto-char here)
      (ispell-complete-word)))
    (when tab
      (let ((completion (try-completion pattern tab)))
	(cond ((null completion)
	       (goto-char here)
	       (message "Can't find completion for \"%s\"" pattern)
	       (ding))
	      ((eq completion t)
	       (goto-char here)
	       (message "[Complete]"))
	      ((not (string= pattern completion))
	       (delete-char (length pattern))
	       (insert completion))
	      (t
	       (goto-char here)
	       (message "Making completion list...")
	       (let ((list (all-completions pattern tab)))
		 (with-output-to-temp-buffer " *Completions*"
		   (display-completion-list list)))
	       (message "Making completion list...%s" "done")))))))

(defun docbook-insert-tag (tag)
  "Insert a tag, reading tag name in minibuffer with completion."
  (interactive
   (list
    (completing-read "Tag: " docbook-all-elements-alist)))
  ;;  (docbook-find-context-of (point))
  ;;  (assert (null docbook-markup-type))
  ;; Fix white-space before tag
  ;;  (unless (docbook-element-data-p (docbook-parse-to-here))
  (skip-chars-backward " \t")
  (cond
   ((looking-at "^\\s-*$")
    (docbook-electric-tab))
   ((looking-at "^\\s-*</")
    (save-excursion
      (insert "\n"))
    (docbook-electric-tab))
   ((looking-at "$")
    (insert "\n")
    (docbook-electric-tab)))
  (let ((tag-type (nth 1 (assoc tag docbook-all-elements-alist))))
    (cond
     ((equal tag-type "block")
      (insert "<")
      (insert tag)
      (insert ">")
      (save-excursion
	(insert "\n")
	(docbook-electric-tab)
	(insert "<")
	(if (looking-at "<")
	    (progn
	      (insert "\n")
	      (backward-char)))
	(docbook-electric-slash)))
     ((equal tag-type "inline")
      (insert "<")
      (insert tag)
      (insert ">")
      (save-excursion
	(insert "</")
	(insert tag)
	(insert ">")))
     (t
      (insert "<")
      (insert tag)
      (save-excursion
	(insert "/>")))))

  (let ((here (point))
	(auto-insert (assoc tag docbook-all-autoinsert-alist)))
    (if auto-insert
	(progn
	  (insert (car (cdr auto-insert)))
	  (goto-char here)
	  (if (search-forward "^" nil t nil)
	      (if (> (- (point) here) (length (car (cdr auto-insert))))
		  (goto-char here)
		(progn
		  (forward-char -1)
		  (delete-char 1)))
	    (goto-char here))))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Syntax table stuff

(defvar docbook-mode-syntax-table nil
  "Syntax table used while in DOCBOOK mode.")

(if docbook-mode-syntax-table
    ()
  (setq docbook-mode-syntax-table (make-syntax-table))
  ;; set the non-alphanumeric characters in XML names to
  ;; 'symbol constituent' class
  (modify-syntax-entry ?: "_" docbook-mode-syntax-table)
  (modify-syntax-entry ?_ "_" docbook-mode-syntax-table)
  (modify-syntax-entry ?- "_ 1234" docbook-mode-syntax-table)
  (modify-syntax-entry ?. "_" docbook-mode-syntax-table)
  ;; "-" is a special case because it is the first and second characters
  ;; of the start- and end-comment sequences.
  (modify-syntax-entry ?- "_ 1234" docbook-mode-syntax-table)
  ;; "%" does double duty in parameter entity declarations and references.
  ;; Not necessary to make "%" and ";" act like parentheses since the
  ;; font lock highlighting tells you when you've put the ";" on the
  ;; end of a parameter entity reference.
  (modify-syntax-entry ?% "_" docbook-mode-syntax-table)
  (modify-syntax-entry ?\; "_" docbook-mode-syntax-table)
  ;; "/" is just punctuation in DOCBOOKs, and really only has a role in
  ;; Formal Public Identifiers
  (modify-syntax-entry ?/ "." docbook-mode-syntax-table)
  ;; Sometimes a string is more than just a string, Dr Freud.
  ;; Unfortunately, the syntax stuff isn't fussy about matching
  ;; on paired delimeters, and will happily match a single quote
  ;; with a double quote, and vice versa.  At least the font
  ;; lock stuff is more fussy and won't change colour if the
  ;; delimiters aren't paired.
  (modify-syntax-entry ?\" "$" docbook-mode-syntax-table)
  (modify-syntax-entry ?\' "$" docbook-mode-syntax-table)
  ;; The occurrence indicators and connectors are punctuation to us.
  (modify-syntax-entry ?| "." docbook-mode-syntax-table)
  (modify-syntax-entry ?, "." docbook-mode-syntax-table)
  (modify-syntax-entry ?& "." docbook-mode-syntax-table)
  (modify-syntax-entry ?? "." docbook-mode-syntax-table)
  (modify-syntax-entry ?+ "." docbook-mode-syntax-table)
  (modify-syntax-entry ?* "." docbook-mode-syntax-table)
  ;; `<' and `>' are also punctuation
  (modify-syntax-entry ?< "." docbook-mode-syntax-table)
  (modify-syntax-entry ?> "." docbook-mode-syntax-table)
  ;; "#" is syntax too
  (modify-syntax-entry ?# "_" docbook-mode-syntax-table))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; grep stuff

;;;###autoload
(defun docbook-grep (pattern filespec)
  "Grep for PATTERN in files matching FILESPEC.

Runs `grep' with PATTERN and FILESPEC as arguments.

PATTERN is the pattern on which `grep' is to match.  PATTERN is quoted
with single quotes in the `grep' command arguments to avoid
interpretation of characters in PATTERN.  `docbook-grep' maintains a
history of PATTERNs so you can easily re-use a previous value.

FILESPEC is the names or regular expression for the files to be
scanned by grep.  Since `docbook-grep' uses `grep', regular expressions
and multiple filenames are supported, and \"*.docbook\" and \"*.DOCBOOK
*.ent\" are both valid FILESPEC values.

When called interactively, the initial FILESPEC is taken from
docbook-default-filespec, but `docbook-grep' also maintains a history of
FILESPEC arguments so you can easily re-use a previous value.  The
history is shared with `docbook-etags' so you can re-use the same FILESPEC
with both functions.
"
  (interactive
   (list
    (docbook-read-from-minibuffer "Pattern: "
			      (find-tag-default)
			      'docbook-grep-pattern-history)
    (docbook-read-from-minibuffer "Files: "
			      (car docbook-filespec-history)
			      'docbook-filespec-history)))
  ;; We include "--" in the command in case the pattern starts with "-"
  (grep (format "grep -n %s -- '%s' %s"
		(if (not docbook-grep-case-sensitive-flag)
		    "-i")
		pattern
		filespec)))


;;;###autoload
(defun docbook-mode ()
  "Major mode for editing DOCBOOK stylesheets.

Special commands:
\\{docbook-mode-map}
Turning on DOCBOOK mode calls the value of the variable `docbook-mode-hook',
if that value is non-nil.

Abbreviations:

DOCBOOK mode includes a comprehensive set of DOCBOOK-specific abbreviations
preloaded into the abbreviations table.

Font lock mode:

Turning on font lock mode causes various DOCBOOK syntactic structures to be 
hightlighted. To turn this on whenever you visit an DOCBOOK file, add
the following to your .emacs file:
  \(add-hook 'docbook-mode-hook 'turn-on-font-lock\)
"
  (interactive)
  (kill-all-local-variables)
  (use-local-map docbook-mode-map)
  (setq mode-name "DOCBOOK")
  (setq major-mode 'docbook-mode)
  (setq local-abbrev-table docbook-mode-abbrev-table)
  (make-local-variable 'font-lock-defaults)
  (setq font-lock-defaults '(docbook-font-lock-keywords t))
  (setq font-lock-mark-block-function 'docbook-font-lock-mark-block-function)
  (set-syntax-table docbook-mode-syntax-table)
  (run-hooks 'docbook-mode-hook))


;;;; Bug reporting

(eval-and-compile
  (autoload 'reporter-submit-bug-report "reporter"))

(defun docbook-submit-bug-report ()
  "Submit via mail a bug report on DOCBOOKIDE."
  (interactive)
  (and (y-or-n-p "Do you really want to submit a report on DOCBOOK mode? ")
       (reporter-submit-bug-report
	docbookide-maintainer-address
	(concat "docbookide.el " docbookide-version)
	(list 
	 )
	nil
	nil
     "Please change the Subject header to a concise bug description.\nRemember to cover the basics, that is, what you expected to\nhappen and what in fact did happen.  Please remove these\ninstructions from your message.")
    (save-excursion
      (goto-char (point-min))
      (mail-position-on-field "Subject")
      (beginning-of-line)
      (delete-region (point) (progn (forward-line) (point)))
      (insert
       "Subject: DOCBOOKIDE version " docbookide-version " is wonderful but...\n"))))


;;;; Last provisions
;;;(provide 'docbookide)

;;; docbookide.el ends here

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -