File: tu-comment.el

package info (click to toggle)
xemacs20 20.4-13
  • links: PTS
  • area: main
  • in suites: slink
  • size: 67,324 kB
  • ctags: 57,643
  • sloc: lisp: 586,197; ansic: 184,662; sh: 4,296; asm: 3,179; makefile: 2,021; perl: 1,059; csh: 96; sed: 22
file content (128 lines) | stat: -rw-r--r-- 4,221 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
;;; tu-comment.el --- a comment out utility for Lisp programs.

;; Copyright (C) 1995,1996 MORIOKA Tomohiko

;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
;; Created: 1995/10/27
;; Version: $Id: tu-comment.el,v 4.0 1996/09/02 12:58:05 morioka Exp $
;; Keywords: comment, Lisp

;; This file is part of tl (Tiny Library).

;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2, or (at
;; your option) any later version.

;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;; General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING.  If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.

;;; Commentary:

;; - How to install.
;;   1. bytecompile this file and copy it to the apropriate directory.
;;   2. put the following lines to your ~/.emacs:
;;		(autoload 'comment-sexp "tu-comment" nil t)
;;		(global-set-key "\C-c\C-q" 'comment-sexp)
;; - How to use.
;;      type `C-c C-q' at the beginning of S-expression you want to
;;      comment out.

;;; Code:

(defvar comment-sexp-first-line-method-alist
  '((emacs-lisp-mode       . comment-sexp-middle-line-method-for-lisp)
    (lisp-interaction-mode . comment-sexp-middle-line-method-for-lisp)
    (lisp-mode             . comment-sexp-middle-line-method-for-lisp)
    (scheme-mode           . comment-sexp-middle-line-method-for-lisp)
    (c-mode                . comment-sexp-first-line-method-for-c)
    (c++-mode              . comment-sexp-middle-line-method-for-c++)
    ))

(defvar comment-sexp-middle-line-method-alist
  '((emacs-lisp-mode       . comment-sexp-middle-line-method-for-lisp)
    (lisp-interaction-mode . comment-sexp-middle-line-method-for-lisp)
    (lisp-mode             . comment-sexp-middle-line-method-for-lisp)
    (scheme-mode           . comment-sexp-middle-line-method-for-lisp)
    (c-mode                . comment-sexp-middle-line-method-for-c)
    (c++-mode              . comment-sexp-middle-line-method-for-c++)
    ))

(defvar comment-sexp-last-line-method-alist
  '((emacs-lisp-mode       . comment-sexp-last-line-method-for-dummy)
    (lisp-interaction-mode . comment-sexp-last-line-method-for-dummy)
    (lisp-mode             . comment-sexp-last-line-method-for-dummy)
    (scheme-mode           . comment-sexp-last-line-method-for-dummy)
    (c-mode                . comment-sexp-last-line-method-for-c)
    (c++-mode              . comment-sexp-last-line-method-for-dummy)
    ))

(defun comment-sexp-middle-line-method-for-lisp ()
  (insert ";; ")
  )

(defun comment-sexp-middle-line-method-for-c++ ()
  (insert "// ")
  )

(defun comment-sexp-first-line-method-for-c ()
  (insert "/* ")
  )

(defun comment-sexp-middle-line-method-for-c ()
  (insert " * ")
  )

(defun comment-sexp-last-line-method-for-c (c)
  (insert "\n")
  (while (< 0 c)
    (insert " ")
    (setq c (1- c))
    )
  (insert " */")
  )

(defun comment-sexp-last-line-method-for-dummy (c))

(defun comment-sexp ()
  (interactive)
  (let ((c (current-column))
        (b (save-excursion
             (beginning-of-line)
             (point)))
        (e (save-excursion
             (forward-sexp)
             (point)
             ))
        )
    (save-excursion
      (save-restriction
        (narrow-to-region b e)
        (untabify b e)
        
        (beginning-of-line)
        (move-to-column c)
        (funcall
         (cdr (assq major-mode comment-sexp-first-line-method-alist)))
        (forward-line)
        
        (while (< (point) (point-max))
          (beginning-of-line)
          (move-to-column c)
          (funcall
           (cdr (assq major-mode comment-sexp-middle-line-method-alist)))
          (forward-line)
          )
        
        (funcall
         (cdr (assq major-mode comment-sexp-last-line-method-alist)) c)
        ))))

;;; tu-comment.el ends here