I am trying to match a Perl identifier at the point, like My::Module::dummy_func
. I'd like to start simple and require a valid identifier as follows:
- restricted to a single line
- starts with a space
- ends with a (
So if point is at a colon in this line:
my $a = My::Module::dummy_func(3)
I should get a match equal to My::Module::dummy_func
.
Here is what I have
(defun get-perl-id-at-point ()
(interactive)
(let ((beg nil) (end nil))
(save-excursion
(if (re-search-forward "[A-Za-z0-9:_]*?(" (line-end-position) t)
(setq end (- (point) 1))))
(save-excursion
(if (re-search-backward " [A-Za-z0-9:_]*?" (line-beginning-position) t)
(setq beg (+ (point) 1))))
(if (and beg end)
(message (buffer-substring beg end)))))
This works for example if point is at a :
, but if point is at the $
in $a
I get $a = My::Module::dummy_func
whereas I would like to get a no match..
How can this be done?