diff options
| author | Alan Mackenzie | 2018-08-26 11:05:22 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2018-08-26 11:05:22 +0000 |
| commit | 5c642b2dc1b666ae488225b76251750a8cf331be (patch) | |
| tree | 9a431d2db895d6059fe4b29fdaf9edeefe939230 | |
| parent | 0edf60583245cc6f3fd53ddae2f21748a4a1b239 (diff) | |
| download | emacs-5c642b2dc1b666ae488225b76251750a8cf331be.tar.gz emacs-5c642b2dc1b666ae488225b76251750a8cf331be.zip | |
CC Mode: make c-display-defun-name work with a pointer return type.
Fixes bug #32403.
* lisp/progmodes/cc-cmds.el (c-in-function-trailer-p): No longer insist on
c-beginning-of-decl-1 returning 'same.
(c-where-wrt-brace-construct): Tighten up the test for looking at a symbol by
excluding keywords. When point is after a }, do not return 'at-function-end
for a struct/union/class/...
(c-defun-name-1): Considerably simplify, by amalgamating the two cond arms
which find structs etc., and by using functions like c-forward-declarator
rather than the faulty analysis of the source by hand.
| -rw-r--r-- | lisp/progmodes/cc-cmds.el | 83 |
1 files changed, 30 insertions, 53 deletions
diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el index 31cf0b11596..478ccf18029 100644 --- a/lisp/progmodes/cc-cmds.el +++ b/lisp/progmodes/cc-cmds.el | |||
| @@ -1383,7 +1383,7 @@ No indentation or other \"electric\" behavior is performed." | |||
| 1383 | (let ((eo-block (point)) | 1383 | (let ((eo-block (point)) |
| 1384 | bod) | 1384 | bod) |
| 1385 | (and (eq (char-before) ?\}) | 1385 | (and (eq (char-before) ?\}) |
| 1386 | (eq (car (c-beginning-of-decl-1 lim)) 'previous) | 1386 | (memq (car (c-beginning-of-decl-1 lim)) '(same previous)) |
| 1387 | (setq bod (point)) | 1387 | (setq bod (point)) |
| 1388 | ;; Look for struct or union or ... If we find one, it might | 1388 | ;; Look for struct or union or ... If we find one, it might |
| 1389 | ;; be the return type of a function, or the like. Exclude | 1389 | ;; be the return type of a function, or the like. Exclude |
| @@ -1445,10 +1445,17 @@ No indentation or other \"electric\" behavior is performed." | |||
| 1445 | (consp paren-state) | 1445 | (consp paren-state) |
| 1446 | (consp (car paren-state)) | 1446 | (consp (car paren-state)) |
| 1447 | (eq start (cdar paren-state)) | 1447 | (eq start (cdar paren-state)) |
| 1448 | (not | 1448 | (or |
| 1449 | (progn | 1449 | (save-excursion |
| 1450 | (c-forward-syntactic-ws) | 1450 | (c-forward-syntactic-ws) |
| 1451 | (looking-at c-symbol-start)))) | 1451 | (or (not (looking-at c-symbol-start)) |
| 1452 | (looking-at c-keywords-regexp))) | ||
| 1453 | (save-excursion | ||
| 1454 | (goto-char (caar paren-state)) | ||
| 1455 | (c-beginning-of-decl-1 | ||
| 1456 | (and least-enclosing | ||
| 1457 | (c-safe-position least-enclosing paren-state))) | ||
| 1458 | (not (looking-at c-defun-type-name-decl-key))))) | ||
| 1452 | 'at-function-end) | 1459 | 'at-function-end) |
| 1453 | (t | 1460 | (t |
| 1454 | ;; Find the start of the current declaration. NOTE: If we're in the | 1461 | ;; Find the start of the current declaration. NOTE: If we're in the |
| @@ -1841,7 +1848,7 @@ or NIL if there isn't one. \"Defun\" here means a function, or | |||
| 1841 | other top level construct with a brace block." | 1848 | other top level construct with a brace block." |
| 1842 | (c-save-buffer-state | 1849 | (c-save-buffer-state |
| 1843 | (beginning-of-defun-function end-of-defun-function | 1850 | (beginning-of-defun-function end-of-defun-function |
| 1844 | where pos decl name-start name-end case-fold-search) | 1851 | where pos decl0 decl type-pos tag-pos case-fold-search) |
| 1845 | 1852 | ||
| 1846 | (save-excursion | 1853 | (save-excursion |
| 1847 | ;; Move back out of any macro/comment/string we happen to be in. | 1854 | ;; Move back out of any macro/comment/string we happen to be in. |
| @@ -1861,31 +1868,10 @@ other top level construct with a brace block." | |||
| 1861 | (when (looking-at c-typedef-key) | 1868 | (when (looking-at c-typedef-key) |
| 1862 | (goto-char (match-end 0)) | 1869 | (goto-char (match-end 0)) |
| 1863 | (c-forward-syntactic-ws)) | 1870 | (c-forward-syntactic-ws)) |
| 1871 | (setq type-pos (point)) | ||
| 1864 | 1872 | ||
| 1865 | ;; Pick out the defun name, according to the type of defun. | 1873 | ;; Pick out the defun name, according to the type of defun. |
| 1866 | (cond | 1874 | (cond |
| 1867 | ;; struct, union, enum, or similar: | ||
| 1868 | ((save-excursion | ||
| 1869 | (and | ||
| 1870 | (looking-at c-defun-type-name-decl-key) | ||
| 1871 | (consp (c-forward-decl-or-cast-1 (c-point 'bosws) 'top nil)) | ||
| 1872 | (or (not (or (eq (char-after) ?{) | ||
| 1873 | (and c-recognize-knr-p | ||
| 1874 | (c-in-knr-argdecl)))) | ||
| 1875 | (progn (c-backward-syntactic-ws) | ||
| 1876 | (not (eq (char-before) ?\))))))) | ||
| 1877 | (let ((key-pos (point))) | ||
| 1878 | (c-forward-over-token-and-ws) ; over "struct ". | ||
| 1879 | (cond | ||
| 1880 | ((looking-at c-symbol-key) ; "struct foo { ..." | ||
| 1881 | (buffer-substring-no-properties key-pos (match-end 0))) | ||
| 1882 | ((eq (char-after) ?{) ; "struct { ... } foo" | ||
| 1883 | (when (c-go-list-forward) | ||
| 1884 | (c-forward-syntactic-ws) | ||
| 1885 | (when (looking-at c-symbol-key) ; a bit bogus - there might | ||
| 1886 | ; be several identifiers. | ||
| 1887 | (match-string-no-properties 0))))))) | ||
| 1888 | |||
| 1889 | ((looking-at "DEFUN\\s-*(") ;"DEFUN\\_>") think of XEmacs! | 1875 | ((looking-at "DEFUN\\s-*(") ;"DEFUN\\_>") think of XEmacs! |
| 1890 | ;; DEFUN ("file-name-directory", Ffile_name_directory, Sfile_name_directory, ...) ==> Ffile_name_directory | 1876 | ;; DEFUN ("file-name-directory", Ffile_name_directory, Sfile_name_directory, ...) ==> Ffile_name_directory |
| 1891 | ;; DEFUN(POSIX::STREAM-LOCK, stream lockp &key BLOCK SHARED START LENGTH) ==> POSIX::STREAM-LOCK | 1877 | ;; DEFUN(POSIX::STREAM-LOCK, stream lockp &key BLOCK SHARED START LENGTH) ==> POSIX::STREAM-LOCK |
| @@ -1901,32 +1887,23 @@ other top level construct with a brace block." | |||
| 1901 | (c-backward-syntactic-ws) | 1887 | (c-backward-syntactic-ws) |
| 1902 | (point)))) | 1888 | (point)))) |
| 1903 | 1889 | ||
| 1904 | (t | 1890 | (t ; Normal function or initializer. |
| 1905 | ;; Normal function or initializer. | 1891 | (when (looking-at c-defun-type-name-decl-key) ; struct, etc. |
| 1906 | (when | 1892 | (goto-char (match-end 0)) |
| 1907 | (and | 1893 | (c-forward-syntactic-ws) |
| 1908 | (consp | 1894 | (setq tag-pos (point)) |
| 1909 | (setq decl | 1895 | (goto-char type-pos)) |
| 1910 | (c-forward-decl-or-cast-1 (c-point 'bosws) 'top nil))) | 1896 | (setq decl0 (c-forward-decl-or-cast-1 (c-point 'bosws) 'top nil)) |
| 1911 | (setq name-start (car decl)) | 1897 | (when (consp decl0) |
| 1912 | (progn (if (and (looking-at c-after-suffixed-type-decl-key) | 1898 | (goto-char (car decl0)) |
| 1913 | (match-beginning 1)) | 1899 | (setq decl (c-forward-declarator))) |
| 1914 | (c-forward-keyword-clause 1)) | 1900 | (and decl |
| 1915 | t) | 1901 | (car decl) (cadr decl) |
| 1916 | (or (eq (char-after) ?{) | 1902 | (buffer-substring-no-properties |
| 1917 | (and c-recognize-knr-p | 1903 | (if (eq (car decl) tag-pos) |
| 1918 | (c-in-knr-argdecl))) | 1904 | type-pos |
| 1919 | (goto-char name-start) | 1905 | (car decl)) |
| 1920 | (c-forward-name) | 1906 | (cadr decl))))))))) |
| 1921 | (eq (char-after) ?\()) | ||
| 1922 | (c-backward-syntactic-ws) | ||
| 1923 | (when (eq (char-before) ?\=) ; struct foo bar = {0, 0} ; | ||
| 1924 | (c-backward-token-2) | ||
| 1925 | (c-backward-syntactic-ws)) | ||
| 1926 | (setq name-end (point)) | ||
| 1927 | (c-back-over-compound-identifier) | ||
| 1928 | (and (looking-at c-symbol-start) | ||
| 1929 | (buffer-substring-no-properties (point) name-end))))))))) | ||
| 1930 | 1907 | ||
| 1931 | (defun c-defun-name () | 1908 | (defun c-defun-name () |
| 1932 | "Return the name of the current defun, or NIL if there isn't one. | 1909 | "Return the name of the current defun, or NIL if there isn't one. |