aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/progmodes/cc-cmds.el61
1 files changed, 52 insertions, 9 deletions
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 @@
7;; 1985 Richard M. Stallman 7;; 1985 Richard M. Stallman
8;; Maintainer: cc-mode-help@python.org 8;; Maintainer: cc-mode-help@python.org
9;; Created: 22-Apr-1997 (split from cc-mode.el) 9;; Created: 22-Apr-1997 (split from cc-mode.el)
10;; Version: 5.14 10;; Version: 5.15
11;; Keywords: c languages oop 11;; Keywords: c languages oop
12 12
13;; This file is part of GNU Emacs. 13;; This file is part of GNU Emacs.
@@ -354,17 +354,28 @@ the brace is inserted inside a literal."
354 354
355(defun c-electric-slash (arg) 355(defun c-electric-slash (arg)
356 "Insert a slash character. 356 "Insert a slash character.
357If slash is second of a double-slash C++ style comment introducing 357
358construct, and we are on a comment-only-line, indent line as comment. 358Indent the line as a comment, if:
359
360 1. The slash is second of a `//' line oriented comment introducing
361 token and we are on a comment-only-line, or
362
363 2. The slash is part of a `*/' token that closes a block oriented
364 comment.
365
359If numeric ARG is supplied or point is inside a literal, indentation 366If numeric ARG is supplied or point is inside a literal, indentation
360is inhibited." 367is inhibited."
361 (interactive "P") 368 (interactive "P")
362 (let ((indentp (and (not arg) 369 (let* ((ch (char-before))
363 (eq (char-before) ?/) 370 (indentp (and (not arg)
364 (eq last-command-char ?/) 371 (eq last-command-char ?/)
365 (not (c-in-literal)))) 372 (or (and (eq ch ?/)
366 ;; shut this up 373 (not (c-in-literal)))
367 (c-echo-syntactic-information-p nil)) 374 (and (eq ch ?*)
375 (c-in-literal)))
376 ))
377 ;; shut this up
378 (c-echo-syntactic-information-p nil))
368 (self-insert-command (prefix-numeric-value arg)) 379 (self-insert-command (prefix-numeric-value arg))
369 (if indentp 380 (if indentp
370 (c-indent-line)))) 381 (c-indent-line))))
@@ -735,6 +746,38 @@ comment."
735 comment-column)) 746 comment-column))
736 ))))) 747 )))))
737 748
749;; for proposed new variable comment-line-break-function
750(defun c-comment-line-break-function (&optional soft)
751 ;; we currently don't do anything with soft line breaks
752 (if (not c-comment-continuation-stars)
753 (indent-new-comment-line soft)
754 (let ((here (point))
755 (leader c-comment-continuation-stars))
756 (back-to-indentation)
757 ;; are we looking at a block or lines style comment?
758 (if (and (looking-at (concat "\\(" c-comment-start-regexp "\\)[ \t]+"))
759 (string-equal (match-string 1) "//"))
760 ;; line style
761 (setq leader "// "))
762 (goto-char here)
763 (delete-region (progn (skip-chars-backward " \t") (point))
764 (progn (skip-chars-forward " \t") (point)))
765 (newline)
766 ;; to avoid having an anchored comment that c-indent-line will
767 ;; trip up on
768 (insert " " leader)
769 (c-indent-line))))
770
771;; advice for indent-new-comment-line for older Emacsen
772(if (boundp 'comment-line-break-function)
773 nil
774 (require 'advice)
775 (defadvice indent-new-comment-line (around c-line-break-advice activate)
776 (if (or (not c-buffer-is-cc-mode)
777 (not c-comment-continuation-stars))
778 ad-do-it
779 (c-comment-line-break-function (ad-get-arg 0)))))
780
738;; used by outline-minor-mode 781;; used by outline-minor-mode
739(defun c-outline-level () 782(defun c-outline-level ()
740 (save-excursion 783 (save-excursion