This file is indexed.

/usr/share/emacs/site-lisp/smartdoc/sdoc-helper.el is in smartdoc-elisp 1.0-5.

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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
;;
;; SmartDoc helper functions
;;
;; @since   Jul. 15, 2000
;; @version Apr.  1, 2001
;; @author  ASAMI, Tomoharu (asami@zeomtech.com)
;;

(defvar sdoc-encodings '(("UTF-8" . nil)
			 ("us-ascii" . nil)
			 ("ISO-8859-1" . iso-8859-1)
			 ("Shift_JIS" . sjis)
			 ("EUC-JP" . euc-jp)
			 ("ISO-2022-JP" . iso-2022-jp)))

(defvar sdoc-languages '(("en" . ("UTF-8"
				  "us-ascii"
				  "ISO-8859-1"))
			 ("ja" . ("UTF-8"
				  "Shift_JIS"
				  "EUC-JP"
				  "ISO-2022-JP"))))

(defvar sdoc-entity-alist
  '(("\\\\" . "\")        ; 005C
    ("$B!=(B" . "―")        ; 2015
    ("~" . "˜")          ; 007E
;    ("" . "&wdash;")          ; 301C
;    ("" . "&dvline;")         ; 2016
    ("$B!1(B" . "&fmacron;")       ; FFE3
    ("$B!@(B" . "&fbsol;")         ; FF3C
    ("$B!A(B" . "&ftild;")         ; FF5E
    ("$B!B(B" . "&fparato;")       ; 2225
    ("$B!](B" . "&fminus;")        ; FF0D
    ("$B!q(B" . "&fcent;")         ; FFE0
    ("$B!r(B" . "&fpoun;")         ; FFE1
    ("$B!o(B" . "&fyen;")          ; FFE5
    ("$B"L(B" . "&fnot;")          ; FFE2
;    ("" . "&fbrvbar;")       ; FFE4 XXX invalid character in emacs
    )
  "Symbols to use entities instead of raw characters.")

(defun sdoc-compile (&optional arg)
  (interactive "P")
  (if arg
      (sdoc-preview-plain)
    (sdoc-compile-all)))

(defun sdoc-compile-all ()
  (interactive)
  (if (not (boundp 'compile-command))	; by kiyoka@netfort.gr.jp
      (progn				; [sdocusersj 246]
	(setq compile-command "make -k")
	(setq compilation-read-command t)
	))
  (let
      ((buf1 compile-command)
       (buf2 compilation-read-command))
    (compile (concat "sdoc" " " buffer-file-name))
    (setq compile-command buf1)
    (setq compilation-read-command buf2)))

(defun sdoc-preview-plain ()
  (interactive)
  (let (buffer proc name)
    (setq filename buffer-file-name)
    (save-excursion
      (setq buffer (get-buffer-create "*SmartDoc preview*"))
      (set-buffer buffer)
      (erase-buffer)
      (message "Now formating ...")
      (setq proc
	    (start-process-shell-command
	     "sdoc" buffer
	     (concat "sdoc -verbose:false -packager:stdout -format:plain "
		     filename)))
      (set-process-sentinel proc (function sdoc-sentinel)))))

(defun sdoc-sentinel (proc msg)
  (let (buffer)
    (setq buffer (process-buffer proc))
    (save-excursion
      (set-buffer buffer)
      (goto-char (point-min))
      (message "Now formating ... Done.")
      (set-buffer-modified-p nil)
      (setq truncate-lines t)
      (pop-to-buffer buffer))))

(defun sdoc-kill-content ()
  (interactive)
  (let (start char)
    (save-excursion
      (cond ((re-search-backward "[<>'\"]" nil t)
	     (setq start (match-end 0))
	     (setq char (char-before start))
	     (goto-char (+ (point) 1))
	     (cond ((char-equal char ?>) ; between tag
		    (cond ((re-search-forward "<")
			   (kill-region start (match-beginning 0)))))
		   ((char-equal char ?<) ; inside tag
		    (cond ((re-search-forward ">")
			   (kill-region start (match-beginning 0)))))
		   ((char-equal char ?\") ; between double quotation
		    (cond ((re-search-forward "\"")
			   (kill-region start (match-beginning 0)))))
		   ((char-equal char ?\') ; between single quotation
		    (cond ((re-search-forward "\'")
			   (kill-region start (match-beginning 0)))))))))))

(defun sdoc-use-entities ()
  (interactive)
  (mapcar (function
	   (lambda (cell)
	     (let (start symbol entity)
	       (setq symbol (car cell))
	       (setq entity (cdr cell))
	       (save-excursion
		 (goto-char (point-min))
		 (while (re-search-forward symbol nil t)
		   (setq start (match-beginning 0))
		   (kill-region start (match-end 0))
		   (goto-char start)
		   (insert entity))))))
	  sdoc-entity-alist))

(defun sdoc-insert-prototype ()
  (interactive)
  (let (encoding lang title)
    (setq lang (completing-read "language : "
				(sdoc-language-candidates)))
    (if (equal lang "")
	(setq lang nil))
    (setq encoding (completing-read "encoding : "
				    (sdoc-encoding-candidates lang)))
    (if (equal encoding "")
	(setq encoding nil))
    (sdoc-set-buffer-encoding encoding)
    (setq title (read-string "title : "))
    (if (equal title "")
	(setq title nil))
    (goto-char 0)
    (insert "<?xml version='1.0'")
    (cond (encoding
	   (insert " encoding='")
	   (insert encoding)
	   (insert "'")))
    (insert " ?>\n")
    (insert "\n")
    (insert "<doc")
    (cond (lang
	   (insert " xml:lang='")
	   (insert lang)
	   (insert "'")))
    (insert ">\n")
    (insert "<head>\n")
    (insert "<title>")
    (if title
	(insert title))
    (insert "</title>\n")
    (insert "</head>\n")
    (insert "<body>\n")
    (insert "\n")
    (insert "</body>\n")
    (insert "</doc>\n")
    (re-search-backward "<body>\n")
    (goto-char (match-end 0))))

(defun sdoc-language-candidates ()
  (mapcar (function
	   (lambda (list)
	     (list (car list))))	; by mit@nines.nec.co.jp
	  sdoc-languages))		; [sdocusersj 178]

(defun sdoc-encoding-candidates (language)
  (let (entry)
    (cond ((null language)
	   "UTF-8")
	  ((equal language "")
	   "UTF-8")
	  ((setq entry (assoc language sdoc-languages))
	   (mapcar (function list) (cdr entry)))
	  (t
	   "UTF-8"))))

(defun sdoc-set-buffer-encoding (encoding)
  (let (entry system)
    (cond ((setq entry (assoc encoding sdoc-encodings))
	   (cond ((setq system (cdr entry))
		  (cond ((functionp 'set-buffer-file-coding-system)
			 (set-buffer-file-coding-system system)))))))))

;;

(defun sdoc-make-table-records ()
  (interactive)
  (let (start finish data)
    (save-excursion
      (cond ((re-search-backward "[>]" nil t)
	     (setq start (+ (match-end 0) 1))
	     (cond ((re-search-forward "[<]" nil t)
		    (setq finish (- (match-end 0) 1))
		    (save-restriction
		      (narrow-to-region start finish)
		      (setq data (sdoc-extract-data-list "[^,]+")))
		    (kill-region start finish)
		    (sdoc-make-table-records-by-data data))))))))

(defun sdoc-extract-data-list (regex)
  (let (list flag start finish data)
    (goto-char (point-min))
    (setq flag t)
    (while flag
      (save-restriction
	(end-of-line)
	(setq finish (point))
	(beginning-of-line)
	(setq start (point))
	(narrow-to-region start finish)
	(setq data (sdoc-extract-data regex))
	(and data
	     (setq list (cons data list))))
      (if (not (eq (forward-line) 0))
	  (setq flag nil)))
    (nreverse list)))

(defun sdoc-extract-data (regex)
  (let (list)
    (while (re-search-forward regex nil t)
      (setq list (cons (buffer-substring
			(match-beginning 0)
			(match-end 0))
		       list)))
    (nreverse list)))

(defun sdoc-make-table-records-by-data (data)
  (mapcar (function (lambda (list)
		      (insert "<tr>\n")
		      (sdoc-make-table-record-by-data list)
		      (insert "</tr>\n")))
	  data))

(defun sdoc-make-table-record-by-data (data)
  (mapcar (function (lambda (cell)
		      (insert "  <td>")
		      (insert cell)
		      (insert "</td>\n")))
	  data))

;;

(defun sdoc-auto-id-title ()
  (interactive)
  (sdoc-auto-id)
  (sdoc-auto-title))

(defun sdoc-auto-id ()
  (interactive)
  (let (value)
    (setq value (sdoc-get-element-attribute "src"))
    (cond (value
	   (setq value (file-name-nondirectory value))
	   (cond ((string-match "\\([^.]+\\)[.]\\([^.]+\\)" value)
		  (setq value (concat
			       (substring value
					  (match-beginning 1)
					  (match-end 1))
			       (sdoc-make-capital-string
				(substring value
					   (match-beginning 2)
					   (match-end 2)))))))
	   (sdoc-set-element-attribute "id" (concat "prog:" value))))))

(defun sdoc-make-capital-string (string)
  (concat (capitalize (substring string 0 1))
	  (substring string 1)))

(defun sdoc-auto-title ()
  (interactive)
  (let (value)
    (setq value (sdoc-get-element-attribute "src"))
    (cond (value
	   (setq value (file-name-nondirectory value))
	   (sdoc-set-element-attribute "title" value)))))

(defun sdoc-get-element-attribute (attr)
  (let (start finish)
    (save-excursion
      (cond ((re-search-backward "[<]" nil t)
	     (setq start (match-end 0))
	     (cond ((re-search-forward "[>]" nil t)
		      (setq finish (match-beginning 0))
		      (goto-char start)
		      (cond ((re-search-forward
			      (concat attr "=['\"]\\([^'\"]*\\)['\"]")
			      finish
			      t)
			     (buffer-substring
			      (match-beginning 1)
			      (match-end 1)))))))))))

(defun sdoc-set-element-attribute (attr value)
  (interactive)
  (let (start finish)
    (save-excursion
      (cond ((re-search-backward "[<]" nil t)
	     (setq start (match-end 0))
	     (cond ((re-search-forward "/?[>]" nil t)
		    (setq finish (match-beginning 0))
		    (goto-char start)
		      (cond ((re-search-forward
			      (concat attr "=['\"]\\([^'\"]*\\)['\"]")
			      finish
			      t)
			     (setq start (match-beginning 1))
			     (setq finish (match-end 1))
			     (kill-region start finish)
			     (goto-char start)
			     (insert value))
			    (t
			     (goto-char finish)
			     (insert
			      (concat " "attr "=\"" value "\"")))))))))))

(defun sdoc-insert-internal-link (&optional arg)
  (interactive "P")
  (if arg
      (sdoc-insert-internal-link-select)
    (sdoc-insert-internal-link-first)))

(defun sdoc-insert-internal-link-first ()
  (interactive)
  (let (id)
    (setq id (sdoc-find-id))
    (sdoc-insert-link (concat "#" id))))

(defun sdoc-insert-internal-link-select ()
  (interactive)
  (let (id ids select)
    (setq id (sdoc-find-id))
    (setq ids (sdoc-find-all-ids))
    (setq select (completing-read
		  (if id
		      (concat "id (" id ") : ")
		    "id : ")
		  ids))
    (sdoc-insert-link (concat "#" select))))

(defun sdoc-insert-link (id)
    (insert "<a href=\"")
    (if id
	(insert id))
    (insert "\">")
    (save-excursion
    (insert "</a>")))

(defun sdoc-find-id ()
  (save-excursion
    (cond ((re-search-forward "id=\"\\([^\"]+\\)\"" nil t)
	   (buffer-substring (match-beginning 1) (match-end 1))))))

(defun sdoc-find-all-ids ()
  (let (ids id title)
    (save-excursion
      (goto-char (point-min))
      (while (re-search-forward "id=\"\\([^\"]+\\)\"" nil t)
	(setq id (buffer-substring (match-beginning 1) (match-end 1)))
	(setq ids (cons (cons id id) ids))))
;	(save-excursion
;	  (goto-char (match-beginning 1))
;	  (setq title (sdoc-get-element-attribute "title")))
;	(if title
;	    (setq ids (cons (cons (concat id " - " title) id) ids))
;	  (setq ids (cons (cons id id) ids)))))
    ids))

(defun sdoc-insert-program (&optional arg)
  (interactive "P")
  (if arg
      (sdoc-insert-program-partial)
    (sdoc-insert-program-whole)))

(defun sdoc-insert-program-whole (&optional filename)
  (interactive)
  (let ()
    (or filename
	(setq filename (read-file-name "file : " "")))
    (insert (concat "<program src=\"" filename "\"/>\n"))
    (save-excursion
      (goto-char (- (point) 5))
      (sdoc-auto-id-title))))

(defun sdoc-insert-program-partial (&optional filename keyword)
  (interactive)
  (let ()
    (or filename
	(setq filename (read-file-name "file : " "")))
    (or keyword
	(setq keyword (read-string "keyword : ")))
    (insert (concat "<program src=\"" filename "\""
		    " normalizer=\"javasrc\" javasrcKeyword=\"" keyword "\""
		    " title=\""))
    (save-excursion
      (insert (concat keyword "\" id=\"prog:" keyword "\"/>\n")))))

(defun sdoc-insert-figure (&optional filename)
  (interactive)
  (let (name)
    (or filename
	(setq filename (read-file-name "file : " "")))
    (setq name (sdoc-get-component-body filename))
    (insert (concat "<figure src=\"" (sdoc-remove-suffix filename) "\""
		    " title=\""))
    (save-excursion
      (insert (concat name "\" id=\"fig:" name "\"/>\n")))))

(defun sdoc-remove-suffix (filename)
  (let (pos)
    (setq pos (string-match "[.]" filename))
    (cond (pos
	   (substring filename 0 pos))
	  (t
	   filename))))

(defun sdoc-get-component-body (filename)
  (let (pos)
    (setq pos (string-match "[^/]+$" filename))
    (cond (pos
	   (sdoc-remove-suffix (substring filename pos)))
	  (t
	   (sdoc-remove-suffix filename)))))

(provide 'sdoc-helper)