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