yuuji@19: ;;; -*- Emacs-Lisp -*- yuuji@19: ;;; comment/uncomment region for emacs. yuuji@50: ;;; comment.el rev.0.1 yuuji@76: ;;; (c) 1992, 2002 by HIROSE Yuuji.(yuuji@yatex.org) yuuji@76: ;;; Last modified Mon Nov 25 18:33:23 2002 on firestorm yuuji@50: yuuji@50: ;;; Rename `comment-region' to `comment-out-region' for standard yuuji@50: ;;; Emacs-19 function. yuuji@19: yuuji@19: (provide 'comment) yuuji@19: yuuji@50: (defvar current-comment-prefix "> " "*Default prefix string") yuuji@19: yuuji@50: (defun cite-region (beg end) yuuji@19: (save-excursion yuuji@50: (goto-char (max beg end)) yuuji@19: (if (bolp) yuuji@19: (forward-line -1)) yuuji@19: (if (string= string "") (setq string current-comment-prefix) yuuji@19: (setq current-comment-prefix string)) yuuji@19: (save-restriction yuuji@50: (narrow-to-region (min beg end) (point)) yuuji@19: (goto-char (point-min)) yuuji@50: (message "%s" string) yuuji@19: (while (re-search-forward "^" nil t) yuuji@19: (replace-match string)) yuuji@19: )) yuuji@19: ) yuuji@19: yuuji@50: (defun comment-out-region (string &optional beg end once) yuuji@50: "Inserts STRING at the beginning of every line in the region specified yuuji@50: BEG and END. yuuji@19: Called interactively, STRING defaults to comment-start (or '> ' if yuuji@19: none is defined) unless a prefix argument is given, in which case it yuuji@19: prompts for a string. Optional second argument ONCE is only for yuuji@19: compatibility for uncomment-region. It has no means now." yuuji@19: (interactive yuuji@19: (list (if current-prefix-arg yuuji@19: (read-string yuuji@19: (concat "String to insert" yuuji@19: (format "(default \"%s\")" current-comment-prefix yuuji@19: " ") yuuji@19: ": ")) yuuji@50: current-comment-prefix))) yuuji@19: (if (not (stringp string)) (setq string current-comment-prefix)) yuuji@50: (cite-region (or beg (region-beginning)) (or end (region-end))) yuuji@19: ) yuuji@19: yuuji@19: yuuji@76: (defun uncomment-out-region (string &optional beg end once) yuuji@19: "Deletes STRING from the beginning of every line in the region. yuuji@19: Called interactively, STRING defaults to comment-start (or '> ' if yuuji@19: none is defined) unless a prefix argument is given, in which case it yuuji@19: prompts for a string. Optional second argument ONCE restricts yuuji@19: deletion to first occurance of STRING on each line." yuuji@19: (interactive yuuji@19: (list (if current-prefix-arg yuuji@19: (read-string yuuji@19: (concat "String to delete" yuuji@19: (format "(default \"%s\")" current-comment-prefix yuuji@19: " ") yuuji@19: ": ")) yuuji@50: current-comment-prefix))) yuuji@19: (if (not (stringp string)) (setq string current-comment-prefix)) yuuji@19: (save-excursion yuuji@19: (save-restriction yuuji@50: (narrow-to-region (or beg (region-beginning)) (or end (region-end))) yuuji@19: (goto-char (point-min)) yuuji@19: (while (re-search-forward (concat "^" string) nil t) yuuji@19: (replace-match "") yuuji@19: (if once (end-of-line))) yuuji@19: )) yuuji@19: ) yuuji@19: yuuji@19: (defun cite-file (filename) yuuji@19: "insert the file with citation string." yuuji@19: (interactive "FCite-file: ") yuuji@19: (let* yuuji@19: ((string yuuji@19: (read-string yuuji@19: (format "Citation string (default \"%s\"): " current-comment-prefix) yuuji@19: )) yuuji@19: (ins-tail (car (cdr (insert-file-contents filename))))) yuuji@19: (save-excursion yuuji@50: (cite-region (point) (+ (point) ins-tail)))) yuuji@19: )