aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2017-11-03 19:45:17 +0000
committerAlan Mackenzie2017-11-03 19:45:17 +0000
commita0d30d6369018deeffcae174a3c615e582de74d3 (patch)
tree3e0f21a0f8aae8b225bdce7f15c36d187690db57
parent383abc8898cbdb46e460adffbccfda8b2236d24e (diff)
downloademacs-a0d30d6369018deeffcae174a3c615e582de74d3.tar.gz
emacs-a0d30d6369018deeffcae174a3c615e582de74d3.zip
Introduce a function to CC Mode which displays the current function name
Remove an erroneous interactive specification from two functions. * lisp/progmodes/cc-cmds.el (c-display-defun-name): New command. (c-defun-name, c-cpp-define-name): Remove interactive specification. * lisp/progmodes/cc-mode.el (c-mode-base-map): Add binding C-c C-z for the new command. * doc/misc/cc-mode.texi (Other Commands): Add documentation for the new command.
-rw-r--r--doc/misc/cc-mode.texi13
-rw-r--r--lisp/progmodes/cc-cmds.el19
-rw-r--r--lisp/progmodes/cc-mode.el3
3 files changed, 32 insertions, 3 deletions
diff --git a/doc/misc/cc-mode.texi b/doc/misc/cc-mode.texi
index c90f6d06bf6..09a86c888d3 100644
--- a/doc/misc/cc-mode.texi
+++ b/doc/misc/cc-mode.texi
@@ -1760,6 +1760,7 @@ file. For commands that you can use to view the effect of your changes,
1760see @ref{Indentation Commands} and @ref{Filling and Breaking}. 1760see @ref{Indentation Commands} and @ref{Filling and Breaking}.
1761 1761
1762For details of the @ccmode{} style system, see @ref{Styles}. 1762For details of the @ccmode{} style system, see @ref{Styles}.
1763
1763@item @kbd{C-c :} (@code{c-scope-operator}) 1764@item @kbd{C-c :} (@code{c-scope-operator})
1764@kindex C-c : 1765@kindex C-c :
1765@findex c-scope-operator 1766@findex c-scope-operator
@@ -1768,6 +1769,18 @@ In C++, it is also sometimes desirable to insert the double-colon scope
1768operator without performing the electric behavior of colon insertion. 1769operator without performing the electric behavior of colon insertion.
1769@kbd{C-c :} does just this. 1770@kbd{C-c :} does just this.
1770 1771
1772@item @kbd{C-c C-z} (@code{c-display-defun-name})
1773@kindex C-c C-z
1774@findex c-display-defun-name
1775@findex display-defun-name (c-)
1776Display the current function name, if any, in the minibuffer.
1777Additionally, if a prefix argument is given, push the function name to
1778the kill ring. If there is no current function,
1779@code{c-display-defun-name} does nothing. In Emacs, you can use this
1780command in the middle of an interactive search if you set the
1781customizable option @code{isearch-allow-scoll} to non-@code{nil}.
1782@xref{Not Exiting Isearch,,,emacs, GNU Emacs Manual}.
1783
1771@item @kbd{C-c C-\} (@code{c-backslash-region}) 1784@item @kbd{C-c C-\} (@code{c-backslash-region})
1772@kindex C-c C-\ 1785@kindex C-c C-\
1773@findex c-backslash-region 1786@findex c-backslash-region
diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el
index ca64b544200..2b663135932 100644
--- a/lisp/progmodes/cc-cmds.el
+++ b/lisp/progmodes/cc-cmds.el
@@ -1821,7 +1821,6 @@ the open-parenthesis that starts a defun; see `beginning-of-defun'."
1821 "Return the name of the current defun, or NIL if there isn't one. 1821 "Return the name of the current defun, or NIL if there isn't one.
1822\"Defun\" here means a function, or other top level construct 1822\"Defun\" here means a function, or other top level construct
1823with a brace block." 1823with a brace block."
1824 (interactive)
1825 (c-save-buffer-state 1824 (c-save-buffer-state
1826 (beginning-of-defun-function end-of-defun-function 1825 (beginning-of-defun-function end-of-defun-function
1827 where pos name-end case-fold-search) 1826 where pos name-end case-fold-search)
@@ -2048,6 +2047,23 @@ with a brace block."
2048 (eq (char-after) ?\{) 2047 (eq (char-after) ?\{)
2049 (cons (point-min) (point-max)))))))) 2048 (cons (point-min) (point-max))))))))
2050 2049
2050(defun c-display-defun-name (&optional arg)
2051 "Display the name of the current CC mode defun and the position in it.
2052With a prefix arg, push the name onto the kill ring too."
2053 (interactive "P")
2054 (save-restriction
2055 (widen)
2056 (c-save-buffer-state ((name (c-defun-name))
2057 (limits (c-declaration-limits t))
2058 (point-bol (c-point 'bol)))
2059 (when name
2060 (message "%s. Line %s/%s." name
2061 (1+ (count-lines (car limits) point-bol))
2062 (count-lines (car limits) (cdr limits)))
2063 (if arg (kill-new name))
2064 (sit-for 3 t)))))
2065(put 'c-display-defun-name 'isearch-scroll t)
2066
2051(defun c-mark-function () 2067(defun c-mark-function ()
2052 "Put mark at end of the current top-level declaration or macro, point at beginning. 2068 "Put mark at end of the current top-level declaration or macro, point at beginning.
2053If point is not inside any then the closest following one is 2069If point is not inside any then the closest following one is
@@ -2092,7 +2108,6 @@ function does not require the declaration to contain a brace block."
2092 2108
2093(defun c-cpp-define-name () 2109(defun c-cpp-define-name ()
2094 "Return the name of the current CPP macro, or NIL if we're not in one." 2110 "Return the name of the current CPP macro, or NIL if we're not in one."
2095 (interactive)
2096 (let (case-fold-search) 2111 (let (case-fold-search)
2097 (save-excursion 2112 (save-excursion
2098 (and c-opt-cpp-macro-define-start 2113 (and c-opt-cpp-macro-define-start
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index b0e5fe47a7c..f74e931a8bb 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -389,7 +389,8 @@ control). See \"cc-mode.el\" for more info."
389 ;;(define-key c-mode-base-map "\C-c\C-v" 'c-version) 389 ;;(define-key c-mode-base-map "\C-c\C-v" 'c-version)
390 ;; (define-key c-mode-base-map "\C-c\C-y" 'c-toggle-hungry-state) Commented out by ACM, 2005-11-22. 390 ;; (define-key c-mode-base-map "\C-c\C-y" 'c-toggle-hungry-state) Commented out by ACM, 2005-11-22.
391 (define-key c-mode-base-map "\C-c\C-w" 'c-subword-mode) 391 (define-key c-mode-base-map "\C-c\C-w" 'c-subword-mode)
392 (define-key c-mode-base-map "\C-c\C-k" 'c-toggle-comment-style)) 392 (define-key c-mode-base-map "\C-c\C-k" 'c-toggle-comment-style)
393 (define-key c-mode-base-map "\C-c\C-z" 'c-display-defun-name))
393 394
394;; We don't require the outline package, but we configure it a bit anyway. 395;; We don't require the outline package, but we configure it a bit anyway.
395(cc-bytecomp-defvar outline-level) 396(cc-bytecomp-defvar outline-level)