Subject: bug#20761: 25.0.50.1, beginning-of-defun matches inside string

From: Andreas Röhler <[email-masked]>
Date: Mon, 08 Jun 2015 11:09:35 +0200

Am 07.06.2015 um 19:21 schrieb Andreas Röhler:
> emacs -Q
>
> With cursor at end of string below:
>
> (defun asdf ()
>   "
> (defun foo1 (&optional beg end)
>   sdsd"
> )
>
> ;;;
>
> C-M-a stops  inside string at "(defun foo1"
>
> GNU Emacs 25.0.50.1 (i686-pc-linux-gnu, GTK+ Version 2.24.23) of 
> 2015-06-07
>
> Solution:
>
> beginning-of-defun-raw must check if being inside string.
>
>
>

This should fix it:

(defun ar-beginning-of-defun (&optional arg)
   "Move to the beginning of a function definition.

Returns position, if successful, nil otherwise

Calls `beginning-of-defun-function', when set "
   (interactive "P")
   (unless (bobp)
     (skip-chars-backward " \t\r\n\f")
     (forward-char -1)
     (let ((pos (car-safe (nth 9 (parse-partial-sexp (point-min) 
(point))))))
       (if beginning-of-defun-function
       (funcall beginning-of-defun-function arg)
     (and pos
          (goto-char pos))))))

Optional arg here is for special needs, switches between class and 
method defs for example.