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

📄 gsdoc.el

📁 GhostScript的源代码
💻 EL
📖 第 1 页 / 共 2 页
字号:
;;============================================================

(defun gs-selfref ()

"Wrap an URL to make it its own link.  This is useful for links that should
be visible when converted to text."

(interactive)

(save-restriction
  (narrow-to-region (region-beginning) (region-end))
  (goto-char (point-min))
  (if (not (looking-at "http:\\|ftp:")) (insert "http://"))
  (setq g~url (buffer-substring (point-min) (point-max)))
  (goto-char (point-min))
  (insert "<a href=\"")
  (goto-char (point-max)) (insert "\">" g~url "</a>")
  )
)

;;============================================================

(defun gs-table ()

"Set up an indented table around this region, leaving plenty of white space
around the table within the HTML.  The number of columns in the table is
hardcoded here as 3, so that number must be changed by hand if the table
has more than 3 columns.  See gs-row-of-table for how rows are built: a
table with N visible columns generally has 2N-1 HTML columns, including the
columns that provide vertical white space."

(interactive)

(save-restriction
  (narrow-to-region (region-beginning) (region-end))
  (indent-rigidly (region-beginning) (region-end) -80)
  (goto-char (point-min))
  (insert (concat
	"\n\n<blockquote><table cellpadding=0 cellspacing=0>\n"
	"<tr><th colspan=3 bgcolor=\"#CCCC00\"><hr><font size=\"+1\">XXXXXXXXXX</font><hr>\n"
	"<tr valign=bottom>\n"
	"\t<th align=left>\n"
	"\t<td>&nbsp;&nbsp;\n"
	"\t<th align=left>\n"
	"<tr>\t<td colspan=3><hr>\n"
	))
  (goto-char (point-max))
  (insert "</table></blockquote>\n")
  )
)

;;============================================================

(defun gs-text-chars ()

"Prepare text for inclusion in HTML by converting \"&\", \"<\", and \">\"  into
their HTML special forms.  The function acts from point to end-of-region or
end-of-buffer, whichever comes first.

This function is NOT idempotent -- running it twice on the same text will
certainly do the wrong thing, unless at first the text contained none of
those characters."

(interactive)
(setq BEGIN (point))

;; Replace significant characters: "&", "<", and ">".

(while (search-forward "&" nil t) (replace-match "&amp;" t t))

(goto-char BEGIN)
(while (search-forward "<" nil t) (replace-match "&lt;" t t))

(goto-char BEGIN)
(while (search-forward ">" nil t) (replace-match "&gt;" t t))

(goto-char BEGIN)
)

;;============================================================

(defun gs-wrap-textfile ()

"Prepare a text file for inclusion between <pre> and </pre>, then put a
header and footer around it.  One would generally run this function on a
buffer containing only an original text file; it is how the original
history and news files were first prepared.  At this point it's likely to
be most useful in preparing new sections for the news document."

(interactive)

(widen)

;; First prepare the entire text by replacing special characters.

(goto-char (point-min))
(gs-text-chars)

;; At the end of the file, end as-is text and add the standard footer.

(goto-char (point-max))
(backward-word 1) (next-line 1) (beginning-of-line)
(delete-region (point) (point-max))
(insert "\n</pre>\n")
(insert-file "Footer.htm")

;; At the beginning of the file, begin as-is text and delete everything
;; up to the identity string (if any), saving the identity string.

(goto-char (point-min))
(insert "<pre>\n") (setq g~pre-point (point))
(setq g~ID " [No pre-existing ID] ")
(if (re-search-forward "^\\$Id:\\( [^ ]+ \\)\\$" nil t) (progn
    (setq g~ID (buffer-substring (match-beginning 1) (match-end 1)))
    (next-line 1) (beginning-of-line) (delete-region g~pre-point (point))
    ))

;; Insert the standard header and fill in the identity string.

(goto-char (point-min)) (insert-file "Header.htm")
(goto-char (point-min)) (search-forward "<!--" nil t)
(delete-horizontal-space) (insert g~ID)
(search-forward "<pre>\n" nil t)
)

;;============================================================

(defun ~gsregion (Tag)

"Tag a region, leaving point at its end and the region around the whole
thing including the new surrounding tags; thus invoking this function twice
successively makes the first invocation the inner tags and the second the
outer.

Not intended for interactive use; for that use gs-tag, which gives a little
bit of additional service."

(interactive)

(if (not (= 0 (length Tag))) (save-restriction
  (narrow-to-region (region-beginning) (region-end))
  (goto-char (point-min)) (insert "<"  Tag ">")
  (goto-char (point-max)) (insert "</" Tag ">")
  (push-mark (point-min) t)
  (goto-char (point-max))
  )
  )
)

;;============================================================

(defun gs-structure ()

"For historical interest only: add structuring commentary to a Ghostscript
HTML file.  It's crude, but it did most of the work.  Future files will
acquire their structure through plagiarism, like any other code.

Now they've all been structured, and this function was used to do it.  The
placement of table-of-contents lines never worked, because most of the
files didn't yet have TOCS.  Now all files that should have TOCs have
properly placed markers, but that's history."

(interactive)

(setq g~thisfile (buffer-name))

(widen)
(goto-char (point-min))

;; Replace the RCS $Id if one can be found in exactly the right format, and
;; otherwise insert one just after the title, along with a warning message.

(if (re-search-forward "<!-- $Id: *\\([^ ]*\\) $ -->" nil t)
    (progn
      (setq Original (buffer-substring (match-beginning 1) (match-end 1)))
      (replace-match g~thisfile t t nil 1)
      )
    (progn
      (search-forward "</title>" nil t) (end-of-line)
      (insert (concat "\n<!-- $Id: " g~thisfile " $ -->"))
      (setq Original "(UNSET by gs-structure)")
      )
    )

(end-of-line)
(insert (concat "\n<!-- Originally: " Original " -->"))

;; Place the visible header marker immediately after <BODY>.

(re-search-forward "<body[^>]*>" nil t)
    (end-of-line) (forward-char 1)
    (insert (concat g~header-begin "\n\n"))

;; Place the headline marker before the first <table> block.

(search-forward "<table" nil t) (search-backward "\n\n" nil t)
    (forward-word 1) (beginning-of-line)
    (insert (concat g~headline-begin "\n\n"))

;; After the first table block place the end-headline marker and both
;; table-of-contents markers, without worrying where the table of contents
;; really is.  The TOC markers can easily be moved by hand later.

(search-forward "\n\n" nil t)
    (backward-word 1) (end-of-line) (forward-char 1)
    (insert (concat
	"\n"
	g~headline-end	"\n\n"
	g~toc-begin	"\n\n"
	g~toc-end	"\n\n"))

;; The hints section begins with the first paragraph after where the TOC
;; markers are placed, and ends with <HR>.  This isn't precise, and in fact
;; fails for several files, but once again only an approximation is needed
;; because it'll be edited by hand later.

(search-forward "<p>" nil t) (beginning-of-line)
    (insert (concat g~hint-begin "\n\n"))

(search-forward "<hr>" nil t) (beginning-of-line)
    (insert (concat g~hint-end "\n\n"))

;; The visible header ends with (and includes) the first <HR>, and the
;; contents begin immediately thereafter.

(search-forward "<hr>\n" nil t)
    (insert (concat "\n" g~header-end "\n\n"))

(forward-word 1) (beginning-of-line)
    (insert (concat g~contents-begin "\n\n"))

;; The contents end before the final <HR> and the trailer begins
;; immediately thereafter.

(goto-char (point-max)) (search-backward "<hr>" nil t)
    (backward-word 1) (end-of-line) (forward-char 1)
    (insert (concat
	"\n"
	g~contents-end	"\n\n"
	g~trailer-begin	"\n\n"))

;; The trailer ends with </BODY>.

(goto-char (point-max)) (search-backward "</body>" nil t)
    (insert (concat "\n" g~trailer-end "\n\n"))

;; We may have introduced trailing whitespace and extra empty lines.
;; Remove them.

(goto-char (point-min))
(while (re-search-forward "[ \t\240\r]+$" nil t) (replace-match "" t t))
(goto-char (point-min))
(while (re-search-forward "\n\n\n+" nil t) (replace-match "\n\n" t t))

)

;;============================================================
;; When this file is loaded into emacs, define the structure markers for GS
;; HTML files.  These markers have two purposes: first, to make the HTML
;; more readable, and second, to enable these functions to locate sections
;; unambiguously (see gs-toc, the table of contents builder).  Note that
;; the markers do not include LF.

(defun g~marker (basic)

"Build a complete Ghostscript HTML file marker from its text-only part.
gs-toc relies entirely on this function, so if it's ever changed, gs-toc
and existing markers would also have to be changed to keep pace.

Intended only for initialization, not interactive use.

All the existing files are now marked up, and since any future ones are
(properly) likely to be created by plagiarism, it's difficult to imagine
why anyone would want to change this unless they want to go to the trouble
of coming up with a much more useful marking scheme."

(interactive)

(setq HEAD (concat "<!-- [" basic "] "))
(concat HEAD
    (substring
    "---------------------------------------------------------------------- -->"
    (- (length HEAD) 80)
    ))
)

;;============================================================
;; Initialization code that must run after functions are defined.
;;
;; Look in a Ghostscript HTML file to see how these markers are used,
;; generally
;;
;;	begin visible header
;;		begin headline
;;		end headline
;;		begin table of contents
;;		end table of contents
;;		begin hint
;;		end hint
;;	end visible header
;;	begin contents
;;	end contents
;;	begin visible trailer
;;	end visible trailer
;;
;; although the TOC is in slightly different positions in a few files.

(defvar g~header-begin		(g~marker "1.0 begin visible header")
	"Begin the HTML file's visible header material")

(defvar g~header-end		(g~marker "1.0 end visible header")
	"End the HTML file's visible header")

(defvar g~headline-begin	(g~marker "1.1 begin headline")
	"Begin the conspicuous headline")

(defvar g~headline-end		(g~marker "1.1 end headline")
	"End the conspicuous headline")

(defvar g~toc-begin		(g~marker "1.2 begin table of contents")
	"Begin the table of contents")

(defvar g~toc-end		(g~marker "1.2 end table of contents")
	"End the table of contents")

(defvar g~hint-begin		(g~marker "1.3 begin hint")
	"Begin the \"for other information\" section")

(defvar g~hint-end		(g~marker "1.3 end hint")
	"End the \"for other information\" section")

(defvar g~contents-begin	(g~marker "2.0 begin contents")
	"Begin the main contents")

(defvar g~contents-end		(g~marker "2.0 end contents")
	"End the main contents")

(defvar g~trailer-begin		(g~marker "3.0 begin visible trailer")
	"Begin the visible standard trailer material")

(defvar g~trailer-end		(g~marker "3.0 end visible trailer")
	"End the visible standard trailer material")

;;============================================================
;; Some working variables

(defvar gs-anchor	"JUNK"		"*Anchor name to insert")
(defvar gs-anchor-file	"JUNKFILE"	"*Anchor filename to insert")
(defvar gs-work-buffer	"*GS work*"	"*Ghostscript working buffer")

⌨️ 快捷键说明

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