comparison lisp/tl/mu-comment.el @ 4:b82b59fe008d r19-15b3

Import from CVS: tag r19-15b3
author cvs
date Mon, 13 Aug 2007 08:46:56 +0200
parents
children
comparison
equal deleted inserted replaced
3:30df88044ec6 4:b82b59fe008d
1 ;;;
2 ;;; mu-comment.el --- a comment out utility for Lisp programs.
3 ;;;
4 ;;; Copyright (C) 1995,1996 MORIOKA Tomohiko
5 ;;;
6 ;;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;;; Created: 1995/10/27
8 ;;; Version:
9 ;;; $Id: mu-comment.el,v 1.1.1.1 1996/12/18 03:55:31 steve Exp $
10 ;;; Keywords: comment, Lisp
11 ;;;
12 ;;; This file is part of tl (Tiny Library).
13 ;;;
14 ;;; This program is free software; you can redistribute it and/or
15 ;;; modify it under the terms of the GNU General Public License as
16 ;;; published by the Free Software Foundation; either version 2, or
17 ;;; (at your option) any later version.
18 ;;;
19 ;;; This program is distributed in the hope that it will be useful,
20 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 ;;; General Public License for more details.
23 ;;;
24 ;;; You should have received a copy of the GNU General Public License
25 ;;; along with This program. If not, write to the Free Software
26 ;;; Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
27 ;;;
28 ;;; Commentary:
29 ;;;
30 ;;; - How to install.
31 ;;; 1. bytecompile this file and copy it to the apropriate directory.
32 ;;; 2. put the following lines to your ~/.emacs:
33 ;;; (autoload 'comment-sexp "mu-comment" nil t)
34 ;;; (global-set-key "\C-c\C-q" 'comment-sexp)
35 ;;; - How to use.
36 ;;; type `C-c C-q' at the beginning of S-expression you want to
37 ;;; comment out.
38 ;;;
39 ;;; Code:
40
41 (defvar comment-sexp-first-line-method-alist
42 '((emacs-lisp-mode . comment-sexp-middle-line-method-for-lisp)
43 (lisp-interaction-mode . comment-sexp-middle-line-method-for-lisp)
44 (lisp-mode . comment-sexp-middle-line-method-for-lisp)
45 (scheme-mode . comment-sexp-middle-line-method-for-lisp)
46 (c-mode . comment-sexp-first-line-method-for-c)
47 (c++-mode . comment-sexp-middle-line-method-for-c++)
48 ))
49
50 (defvar comment-sexp-middle-line-method-alist
51 '((emacs-lisp-mode . comment-sexp-middle-line-method-for-lisp)
52 (lisp-interaction-mode . comment-sexp-middle-line-method-for-lisp)
53 (lisp-mode . comment-sexp-middle-line-method-for-lisp)
54 (scheme-mode . comment-sexp-middle-line-method-for-lisp)
55 (c-mode . comment-sexp-middle-line-method-for-c)
56 (c++-mode . comment-sexp-middle-line-method-for-c++)
57 ))
58
59 (defvar comment-sexp-last-line-method-alist
60 '((emacs-lisp-mode . comment-sexp-last-line-method-for-dummy)
61 (lisp-interaction-mode . comment-sexp-last-line-method-for-dummy)
62 (lisp-mode . comment-sexp-last-line-method-for-dummy)
63 (scheme-mode . comment-sexp-last-line-method-for-dummy)
64 (c-mode . comment-sexp-last-line-method-for-c)
65 (c++-mode . comment-sexp-last-line-method-for-dummy)
66 ))
67
68 (defun comment-sexp-middle-line-method-for-lisp ()
69 (insert ";; ")
70 )
71
72 (defun comment-sexp-middle-line-method-for-c++ ()
73 (insert "// ")
74 )
75
76 (defun comment-sexp-first-line-method-for-c ()
77 (insert "/* ")
78 )
79
80 (defun comment-sexp-middle-line-method-for-c ()
81 (insert " * ")
82 )
83
84 (defun comment-sexp-last-line-method-for-c (c)
85 (insert "\n")
86 (while (< 0 c)
87 (insert " ")
88 (setq c (1- c))
89 )
90 (insert " */")
91 )
92
93 (defun comment-sexp-last-line-method-for-dummy (c))
94
95 (defun comment-sexp ()
96 (interactive)
97 (let ((c (current-column))
98 (b (save-excursion
99 (beginning-of-line)
100 (point)))
101 (e (save-excursion
102 (forward-sexp)
103 (point)
104 ))
105 )
106 (save-excursion
107 (save-restriction
108 (narrow-to-region b e)
109 (untabify b e)
110
111 (beginning-of-line)
112 (move-to-column c)
113 (funcall
114 (cdr (assq major-mode comment-sexp-first-line-method-alist)))
115 (forward-line)
116
117 (while (< (point) (point-max))
118 (beginning-of-line)
119 (move-to-column c)
120 (funcall
121 (cdr (assq major-mode comment-sexp-middle-line-method-alist)))
122 (forward-line)
123 )
124
125 (funcall
126 (cdr (assq major-mode comment-sexp-last-line-method-alist)) c)
127 ))))
128
129 ;;; mu-comment.el ends here