yatex

view comment.el @ 270:1b4e0acd0106

Include newpage.rb.
author HIROSE Yuuji <yuuji@gentei.org>
date Thu, 10 May 2012 11:10:13 +0900
parents b1e036697b20
children
line source
1 ;;; -*- Emacs-Lisp -*-
2 ;;; comment/uncomment region for emacs.
3 ;;; comment.el rev.0.1
4 ;;; (c) 1992, 2002 by HIROSE Yuuji.(yuuji@yatex.org)
5 ;;; Last modified Mon Nov 25 18:33:23 2002 on firestorm
7 ;;; Rename `comment-region' to `comment-out-region' for standard
8 ;;; Emacs-19 function.
10 (provide 'comment)
12 (defvar current-comment-prefix "> " "*Default prefix string")
14 (defun cite-region (beg end)
15 (save-excursion
16 (goto-char (max beg end))
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
22 (narrow-to-region (min beg end) (point))
23 (goto-char (point-min))
24 (message "%s" string)
25 (while (re-search-forward "^" nil t)
26 (replace-match string))
27 ))
28 )
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.
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 ": "))
44 current-comment-prefix)))
45 (if (not (stringp string)) (setq string current-comment-prefix))
46 (cite-region (or beg (region-beginning)) (or end (region-end)))
47 )
50 (defun uncomment-out-region (string &optional beg end once)
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 ": "))
63 current-comment-prefix)))
64 (if (not (stringp string)) (setq string current-comment-prefix))
65 (save-excursion
66 (save-restriction
67 (narrow-to-region (or beg (region-beginning)) (or end (region-end)))
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 )
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
85 (cite-region (point) (+ (point) ins-tail))))
86 )