emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] emacs-26 a0d30d6: Introduce a function to CC Mode which di


From: Alan Mackenzie
Subject: [Emacs-diffs] emacs-26 a0d30d6: Introduce a function to CC Mode which displays the current function name
Date: Fri, 3 Nov 2017 15:55:14 -0400 (EDT)

branch: emacs-26
commit a0d30d6369018deeffcae174a3c615e582de74d3
Author: Alan Mackenzie <address@hidden>
Commit: Alan Mackenzie <address@hidden>

    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.
---
 doc/misc/cc-mode.texi     | 13 +++++++++++++
 lisp/progmodes/cc-cmds.el | 19 +++++++++++++++++--
 lisp/progmodes/cc-mode.el |  3 ++-
 3 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/doc/misc/cc-mode.texi b/doc/misc/cc-mode.texi
index c90f6d0..09a86c8 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,
 see @ref{Indentation Commands} and @ref{Filling and Breaking}.
 
 For details of the @ccmode{} style system, see @ref{Styles}.
+
 @item @kbd{C-c :} (@code{c-scope-operator})
 @kindex C-c :
 @findex c-scope-operator
@@ -1768,6 +1769,18 @@ In C++, it is also sometimes desirable to insert the 
double-colon scope
 operator without performing the electric behavior of colon insertion.
 @kbd{C-c :} does just this.
 
address@hidden @kbd{C-c C-z} (@code{c-display-defun-name})
address@hidden C-c C-z
address@hidden c-display-defun-name
address@hidden display-defun-name (c-)
+Display the current function name, if any, in the minibuffer.
+Additionally, if a prefix argument is given, push the function name to
+the kill ring.  If there is no current function,
address@hidden does nothing.  In Emacs, you can use this
+command in the middle of an interactive search if you set the
+customizable option @code{isearch-allow-scoll} to address@hidden
address@hidden Exiting Isearch,,,emacs, GNU Emacs Manual}.
+
 @item @kbd{C-c C-\} (@code{c-backslash-region})
 @kindex C-c C-\
 @findex c-backslash-region
diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el
index ca64b54..2b66313 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'."
   "Return the name of the current defun, or NIL if there isn't one.
 \"Defun\" here means a function, or other top level construct
 with a brace block."
-  (interactive)
   (c-save-buffer-state
       (beginning-of-defun-function end-of-defun-function
        where pos name-end case-fold-search)
@@ -2048,6 +2047,23 @@ with a brace block."
              (eq (char-after) ?\{)
              (cons (point-min) (point-max))))))))
 
+(defun c-display-defun-name (&optional arg)
+  "Display the name of the current CC mode defun and the position in it.
+With a prefix arg, push the name onto the kill ring too."
+  (interactive "P")
+  (save-restriction
+    (widen)
+    (c-save-buffer-state ((name (c-defun-name))
+                         (limits (c-declaration-limits t))
+                         (point-bol (c-point 'bol)))
+      (when name
+       (message "%s.  Line %s/%s." name
+                (1+ (count-lines (car limits) point-bol))
+                (count-lines (car limits) (cdr limits)))
+       (if arg (kill-new name))
+       (sit-for 3 t)))))
+(put 'c-display-defun-name 'isearch-scroll t)
+
 (defun c-mark-function ()
   "Put mark at end of the current top-level declaration or macro, point at 
beginning.
 If 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."
 
 (defun c-cpp-define-name ()
   "Return the name of the current CPP macro, or NIL if we're not in one."
-  (interactive)
   (let (case-fold-search)
     (save-excursion
       (and c-opt-cpp-macro-define-start
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index b0e5fe4..f74e931 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."
   ;;(define-key c-mode-base-map "\C-c\C-v"  'c-version)
   ;; (define-key c-mode-base-map "\C-c\C-y"  'c-toggle-hungry-state)  
Commented out by ACM, 2005-11-22.
   (define-key c-mode-base-map "\C-c\C-w" 'c-subword-mode)
-  (define-key c-mode-base-map "\C-c\C-k" 'c-toggle-comment-style))
+  (define-key c-mode-base-map "\C-c\C-k" 'c-toggle-comment-style)
+  (define-key c-mode-base-map "\C-c\C-z" 'c-display-defun-name))
 
 ;; We don't require the outline package, but we configure it a bit anyway.
 (cc-bytecomp-defvar outline-level)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]