I do not know a shortcut for identifier regexps. Maybe, that is due to the complicated rules that exist for identifiers of some languages.
Nevertheless you can define your own format strings and convert them by
format-spec to regexps with identifiers.
The following lisp code defines a function
my-re for transforming extended regular expressions with
%i as regexp for identifiers to normal regular expressions.
Furthermore, it exemplarily defines
my-re-search-forward for searching with extended regexps.
format-spec implies some constraints:
- if you do not want the identifier regexp at some place where
%i occurs in the search string you have to replace it with
- the regexp may not end with a single
% if that is a really problem you can replace it with something like
(defconst my-identifier-re "\\(?:\\w\\|\\s_\\)\\(?:\\w\\|\\s_\\|[0-9]\\)+"
"Regular expression for identifiers.")
`((?i . ,my-identifier-re)
(?% . "%") ;; escape
;; self-insert all others:
,@(cl-loop for c from 0 upto 255
collect (cons c (string ?% c))))
"Format for format string with ")
(defun my-re (re)
"Transform extended REGEXP into regexp."
(format-spec re my-re-format-with-identifier))
(defun read-interactive (fun)
"Read argument list like `interactive' does."
(call-interactively `(lambda (&rest args)
(defun my-re-search-forward (re &rest args)
"Imitate `re-search-forward' with RE and ARGS but add %i as identifier re."
(interactive (read-interactive 're-search-forward))
(defun my-occur (re &rest args)
"Run `occur' with `re-search-forward' replaced by `my-re-search-froward'."
(interactive (read-interactive 'occur))
(apply #'occur (my-re re) args))
my-occur input for a search for C-function declarations/headers.
It is not complete but covers quite many situations and there are only a few false positives.
]*( *\(%i[&*]? *\)*\(, *\(%i[&*]? *\)+\)*)[[:space:]