19
|
1 ;;; -*- Emacs-Lisp -*-
|
|
2 ;;; comment/uncomment region for emacs.
|
|
3 ;;; comment.el rev.0.0
|
|
4 ;;; (c ) 1992 by Hirose Yuuji.(yuuji@ae.keio.ac.jp)
|
|
5 ;;; Last modified Sat Jan 29 16:55:22 1994 on gloria
|
|
6
|
|
7 (provide 'comment)
|
|
8
|
|
9 (defvar current-comment-prefix "> "
|
|
10 "default prefix string")
|
|
11
|
|
12 (defun cite-region nil
|
|
13 (save-excursion
|
|
14 (if (< (point) (mark)) (exchange-point-and-mark))
|
|
15 (if (bolp)
|
|
16 (forward-line -1))
|
|
17 (if (string= string "") (setq string current-comment-prefix)
|
|
18 (setq current-comment-prefix string))
|
|
19 (save-restriction
|
|
20 (narrow-to-region (point) (mark))
|
|
21 (goto-char (point-min))
|
|
22 (while (re-search-forward "^" nil t)
|
|
23 (message "%s" string)
|
|
24 (replace-match string))
|
|
25 ))
|
|
26 )
|
|
27
|
|
28 (defun comment-region (string &optional once)
|
|
29 "Inserts STRING at the beginning of every line in the region.
|
|
30 Called interactively, STRING defaults to comment-start (or '> ' if
|
|
31 none is defined) unless a prefix argument is given, in which case it
|
|
32 prompts for a string. Optional second argument ONCE is only for
|
|
33 compatibility for uncomment-region. It has no means now."
|
|
34 (interactive
|
|
35 (list (if current-prefix-arg
|
|
36 (read-string
|
|
37 (concat "String to insert"
|
|
38 (format "(default \"%s\")" current-comment-prefix
|
|
39 " ")
|
|
40 ": "))
|
|
41 current-comment-prefix
|
|
42 )))
|
|
43 (if (not (stringp string)) (setq string current-comment-prefix))
|
|
44 (cite-region)
|
|
45 )
|
|
46
|
|
47
|
|
48 (defun uncomment-region (string &optional once)
|
|
49 "Deletes STRING from the beginning of every line in the region.
|
|
50 Called interactively, STRING defaults to comment-start (or '> ' if
|
|
51 none is defined) unless a prefix argument is given, in which case it
|
|
52 prompts for a string. Optional second argument ONCE restricts
|
|
53 deletion to first occurance of STRING on each line."
|
|
54 (interactive
|
|
55 (list (if current-prefix-arg
|
|
56 (read-string
|
|
57 (concat "String to delete"
|
|
58 (format "(default \"%s\")" current-comment-prefix
|
|
59 " ")
|
|
60 ": "))
|
|
61 current-comment-prefix
|
|
62 )))
|
|
63 (if (not (stringp string)) (setq string current-comment-prefix))
|
|
64 (save-excursion
|
|
65 (if (< (point) (mark)) (exchange-point-and-mark))
|
|
66 ; (if (bolp)
|
|
67 ; (forward-line -1))
|
|
68 (save-restriction
|
|
69 (narrow-to-region (point) (mark))
|
|
70 (goto-char (point-min))
|
|
71 (while (re-search-forward (concat "^" string) nil t)
|
|
72 (replace-match "")
|
|
73 (if once (end-of-line)))
|
|
74 ))
|
|
75 )
|
|
76
|
|
77 (defun cite-file (filename)
|
|
78 "insert the file with citation string."
|
|
79 (interactive "FCite-file: ")
|
|
80 (let*
|
|
81 ((string
|
|
82 (read-string
|
|
83 (format "Citation string (default \"%s\"): " current-comment-prefix)
|
|
84 ))
|
|
85 (ins-tail (car (cdr (insert-file-contents filename)))))
|
|
86 (save-excursion
|
|
87 (push-mark (+ (point) ins-tail))
|
|
88 (cite-region)))
|
|
89 )
|