yatex

annotate comment.el @ 141:13a717bee066

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