mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-16 10:50:49 -08:00
(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.
This commit is contained in:
parent
16935765f3
commit
0fc3821efe
1 changed files with 52 additions and 9 deletions
|
|
@ -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,15 +354,26 @@ 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) ?/)
|
||||
(let* ((ch (char-before))
|
||||
(indentp (and (not arg)
|
||||
(eq last-command-char ?/)
|
||||
(not (c-in-literal))))
|
||||
(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))
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue