From: Richard M. Stallman Date: Mon, 11 Aug 1997 22:09:45 +0000 (+0000) Subject: (indent-new-comment-line): Add advice for older Emacs versions if they X-Git-Tag: emacs-20.1~651 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=0fc3821efeda1d8cc8967d30caa1defa0e60350c;p=emacs.git (indent-new-comment-line): Add advice for older Emacs versions if they don't have the variable comment-line-break-function. (c-electric-slash): Make this work as the final slash in a */ block oriented comment closing token. (c-comment-line-break-function): New function for proposed mode-specific comment-line-break-function variable. --- diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el index 97cefb25ca1..cd235fdf100 100644 --- a/lisp/progmodes/cc-cmds.el +++ b/lisp/progmodes/cc-cmds.el @@ -7,7 +7,7 @@ ;; 1985 Richard M. Stallman ;; Maintainer: cc-mode-help@python.org ;; Created: 22-Apr-1997 (split from cc-mode.el) -;; Version: 5.14 +;; Version: 5.15 ;; Keywords: c languages oop ;; This file is part of GNU Emacs. @@ -354,17 +354,28 @@ the brace is inserted inside a literal." (defun c-electric-slash (arg) "Insert a slash character. -If slash is second of a double-slash C++ style comment introducing -construct, and we are on a comment-only-line, indent line as comment. + +Indent the line as a comment, if: + + 1. The slash is second of a `//' line oriented comment introducing + token and we are on a comment-only-line, or + + 2. The slash is part of a `*/' token that closes a block oriented + comment. + If numeric ARG is supplied or point is inside a literal, indentation is inhibited." (interactive "P") - (let ((indentp (and (not arg) - (eq (char-before) ?/) - (eq last-command-char ?/) - (not (c-in-literal)))) - ;; shut this up - (c-echo-syntactic-information-p nil)) + (let* ((ch (char-before)) + (indentp (and (not arg) + (eq last-command-char ?/) + (or (and (eq ch ?/) + (not (c-in-literal))) + (and (eq ch ?*) + (c-in-literal))) + )) + ;; shut this up + (c-echo-syntactic-information-p nil)) (self-insert-command (prefix-numeric-value arg)) (if indentp (c-indent-line)))) @@ -735,6 +746,38 @@ comment." comment-column)) ))))) +;; for proposed new variable comment-line-break-function +(defun c-comment-line-break-function (&optional soft) + ;; we currently don't do anything with soft line breaks + (if (not c-comment-continuation-stars) + (indent-new-comment-line soft) + (let ((here (point)) + (leader c-comment-continuation-stars)) + (back-to-indentation) + ;; are we looking at a block or lines style comment? + (if (and (looking-at (concat "\\(" c-comment-start-regexp "\\)[ \t]+")) + (string-equal (match-string 1) "//")) + ;; line style + (setq leader "// ")) + (goto-char here) + (delete-region (progn (skip-chars-backward " \t") (point)) + (progn (skip-chars-forward " \t") (point))) + (newline) + ;; to avoid having an anchored comment that c-indent-line will + ;; trip up on + (insert " " leader) + (c-indent-line)))) + +;; advice for indent-new-comment-line for older Emacsen +(if (boundp 'comment-line-break-function) + nil + (require 'advice) + (defadvice indent-new-comment-line (around c-line-break-advice activate) + (if (or (not c-buffer-is-cc-mode) + (not c-comment-continuation-stars)) + ad-do-it + (c-comment-line-break-function (ad-get-arg 0))))) + ;; used by outline-minor-mode (defun c-outline-level () (save-excursion