This file is indexed.

/usr/share/emacs/site-lisp/wysihtml/wysidocbookxml.el is in wysihtml-el 0.13-5.1ubuntu2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
;; Routines for "what you see is DocBook XML".
;; copyright 2003,2005-2006 Junichi Uekawa.

;; This file 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.
;;
;; readme-debian.el 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 your Debian installation, in /usr/share/common-licenses/GPL
;; If not, write to the Free Software Foundation, 675 Mass Ave,
;; Cambridge, MA 02139, USA.

(require 'comint)
(require 'elserv)
(require 'mcharset)

(defgroup wysidocbookxml nil 
  "WYSIDocBookXML"
  :group 'sgml
  :prefix "wysidocbookxml-")
(defcustom wysidocbookxml-daemon-name "/usr/lib/wysihtml/wysidocbookdaemon" 
  "The default value for wysidocbookxml daemon."
  :group 'wysidocbookxml
  :type 'file)
(defconst wysidocbookxml-daemon-process-name "wysidocbookxmldaemon-interactive")
(defconst wysidocbookxml-version "0.13"
  "The version number of wysidocbookxml.")
(defcustom wysidocbookxml-elserv-port 8090 "Elserv port used for wysidocbookxml."
  :group 'wysidocbookxml
  :type 'number)
(defcustom wysidocbookxml-mozilla-command-line "iceweasel -remote openurl\\(file:///%s%s\\)" "The command-line used to invoke mozilla remote interface")
(defvar wysidocbookxml-elserv-process nil "The elserv process identifier for the elserv process being used for wysidocbookxml.")
(defvar wysidocbookxml-current-buffer nil 
  "The buffer which is going to be displayed through elserv, for preview.")
(defcustom wysidocbookxml-interactive-time 1
  "The number of seconds to wait before renew.
slow machines may need several seconds, but fast machines may work with  less, for better response time."
  :group 'wysidocbookxml
  :type 'number)
(defcustom wysidocbookxml-xsl-stylesheet "/usr/share/xml/docbook/stylesheet/ldp/html/tldp-one-page.xsl"
  "Filename of stylesheet to use."
  :group 'wysidocbookxml
  :type 'file)
(defvar wysidocbookxml-daemon-buffer nil
  "The buffer that the daemon of wysidocbookdaemon works in.")

(defvar wysidocbookxml-active-modes-alist 
  '((xml-mode . t))
  "*List of major modes that wysidocbookxml mode is activated.")

(defcustom wysidocbookxml-slice-text
  "chapter"
  "The grade of slicing for wysidocbookxml, chapter is probably good enough."
  :group 'wysidocbookxml
  :type 'string)

(defcustom wysidocbookxml-document-format
  "book"
  "The marker for start and end of the whole document. Usually, book
or article."
  :group 'wysidocbookxml
  :type 'string)

(defun wysidocbookxml-start-daemon ()
  "Start up daemon for wysidocbookxml, and assign a buffer for the running process."
  (setq wysidocbookxml-daemon-buffer 
	(make-comint wysidocbookxml-daemon-process-name
		     wysidocbookxml-daemon-name
		     nil
		     "-m" wysidocbookxml-mozilla-command-line 
		     "-x" wysidocbookxml-xsl-stylesheet "-s" (number-to-string wysidocbookxml-interactive-time))))

(defun wysidocbookxml-restart-daemon ()
  "Restart the daemon after reconfiguration."
  (interactive)
  (kill-buffer wysidocbookxml-daemon-buffer)
  (wysidocbookxml-start-daemon))

(defun wysidocbookxml-start-elserv ()
  "Internal routine to start up elserv process.
wysidocbookxml uses this process for providing XML portions to xsltproc."
  (setq wysidocbookxml-elserv-process (elserv-start wysidocbookxml-elserv-port))
  (elserv-publish wysidocbookxml-elserv-process
		  "/preview"
		  :allow '("localhost")
		  :function 'wysidocbookxml-elserv-preview
		  :description "Preview of current XML buffer"))

(defun wysidocbookxml-insert-xml-start ()
  "Insert the required start tag."
  (insert (concat "<" wysidocbookxml-document-format ">")))
  
(defun wysidocbookxml-insert-xml-end ()
  "Insert the required end tag."
  (insert (concat"</" wysidocbookxml-document-format ">")))

(defun wysidocbookxml-elserv-preview (result path ppath request) 
  "View XML slice from buffer.

RESULT is the resulting value
PATH is relative path from the published path
PPATH is the published path
REQUEST is the request data."
  (save-excursion
    (let* ((charset nil)
	   start-slice end-slice text-string header-end header-string)
      (set-buffer wysidocbookxml-current-buffer)
      (save-excursion 
	(setq start-slice (re-search-backward (concat  "<" wysidocbookxml-slice-text "[^>]*>") nil t nil))
	(setq end-slice (re-search-forward (concat  "</" wysidocbookxml-slice-text "[^>]*>") nil t nil))
	(goto-line 1)
	(setq header-end (- 
			  (re-search-forward
			   (concat "<" 
				   wysidocbookxml-document-format
				   "[^>]*>") 
			   nil t nil)
			  (length (match-string 0))))

	(if (or (not end-slice) (not start-slice))
	    (progn 
	      ;; support the case of non-section ... return the whole text if I am at the beginning of text.
	      (setq text-string (buffer-substring-no-properties (point-min) (point-max)))
	      (with-temp-buffer
		(insert text-string)
		(setq charset (detect-mime-charset-region (point-min)(point-max)))
		(elserv-set-result-header 
		 result
		 (list 'content-type (concat "text/xml; charset=" (symbol-name charset))))
		(elserv-set-result-body result 
					(encode-mime-charset-string (buffer-string) charset))))
	  ;; the case of usual secion:
	  (setq text-string (buffer-substring-no-properties start-slice end-slice))
	  (setq header-string (buffer-substring-no-properties 1 header-end))
	  (with-temp-buffer
	    (insert header-string)
	    (wysidocbookxml-insert-xml-start)
	    (insert text-string)
	    (wysidocbookxml-insert-xml-end)
	    (setq charset (detect-mime-charset-region (point-min)(point-max)))
	    (elserv-set-result-header 
	     result
	     (list 'content-type (concat "text/xml; charset=" (symbol-name charset))))
	    (elserv-set-result-body result 
				    (encode-mime-charset-string (buffer-string) charset))))))))

(define-minor-mode wysidocbookxml-mode
  "WYSI Docbook XML minor-mode for auto-previewing of DocBook/XML
through mozilla remote interface"
  nil
  " WYSIDBXML"
  nil
  (if wysidocbookxml-mode
      (progn
	(if (assoc major-mode wysidocbookxml-active-modes-alist)
	    t
	  (setq wysidocbookxml-mode nil)
	  (error "current major-mode is not in wysidocbookxml-active-modes-alist"))
	(if (eq nil wysidocbookxml-daemon-buffer)
	    (wysidocbookxml-start-daemon))
	(wysidocbookxml-daemon-post-command)	;run this once immediately
	(add-hook 'post-command-hook (function wysidocbookxml-daemon-post-command)
		  nil t))
    (progn
      (remove-hook 'post-command-hook (function wysidocbookxml-daemon-post-command)))))

(defun wysidocbookxml-daemon-post-command ()
  "Wysidocbookxml that is invoked after `post-command-hook'."
  (if (not wysidocbookxml-mode)
      t
    (if (local-variable-p 'wysidocbookxml-daemon-buffer-modified-tick (current-buffer))
	t
      (make-local-variable 'wysidocbookxml-daemon-buffer-modified-tick))
    (if (assoc major-mode wysidocbookxml-active-modes-alist)
	(let* ((curval (buffer-modified-tick)))
	  ;; check if all conditions are met.
	  (if (and (boundp 'wysidocbookxml-daemon-buffer-modified-tick)
		   (= curval wysidocbookxml-daemon-buffer-modified-tick)
		   (not (assoc last-command '((recenter . t)))))
	      t				;nothing should be done.
	    ;; otherwise, queue for the redrawing of the page.
	    (setq wysidocbookxml-daemon-buffer-modified-tick curval) 
	    (wysidocbookxml-daemon-preview-page))))))

(defun wysidocbookxml-daemon-preview-page ()
  "Preview the current buffer through xsltproc and mozilla.
Slice the current file and provide it through http."
  (if (or (eq nil wysidocbookxml-elserv-process)
	  (eq 'exit (process-status wysidocbookxml-elserv-process)))
      (wysidocbookxml-start-elserv))
  (setq wysidocbookxml-current-buffer (current-buffer))
  (save-excursion
    (let* ((deactivate-mark nil)
	   (optional-name "#"))
      (if (re-search-backward " [iI][dD]=\"?\\([^>\" ]*\\)" nil t nil)
	  (setq optional-name (concat "#" (match-string 1))))
      (set-buffer wysidocbookxml-daemon-buffer)
      (insert 
       (concat "http://localhost:" (number-to-string wysidocbookxml-elserv-port) "/preview/index.xml " 
	       optional-name))
      (comint-send-input))))

(provide 'wysidocbookxml)