# Set the mark at the beginning of the current function definition

I want this function: assume that I am inside a function, and in line 100, now I want to go to the definition of this function, say 80, and set mark, then go back to 100. So now I have an active region between 80 and 100. I write this function like this:

(defun my-select-fun ()
(interactive)
(setq myline 'line-number-at-pos )
(beginning-of-defun)
(set-mark)
(goto-line myline)
)


But it is not working, and I get an error: Wrong number of arguments: (1 . 1), 0. Sorry for not be familiar with emacs lisp, could someone help me to implement this simple function? Thank you very much.

• line-number-at-pos is a function, you should use (line-number-at-pos). – stackunderflow Dec 28 '16 at 7:18
• The title of your question should be more indicative. – Name Dec 28 '16 at 11:10
• You should report the full error message, which no doubt told you which function was passed the wrong number of arguments (set-mark requires a position argument). – Drew Dec 28 '16 at 16:25

The function set-mark takes an argument, POS, and you didn't supply one. That's why you're getting the error. Have a look at the docs for set-mark (using C-h f set-mark). You probably want (push-mark (point)) instead.

• push-mark  does not work like I expected. Anyway, I still use set-mark, which solved this problem. Thank you though. – Zimou Zhang Dec 28 '16 at 16:27

As jeffkowalski mentioned, you have to pass the position as an argument. And I think you can't use set-mark for this.

(defun my-select-fun (arg)
(interactive "P")
(let ((myline (line-number-at-pos))))
(beginning-of-defun)
(set-mark-command arg)
(goto-line myline)))

• Thank you, but what is arg? I don't want any arguments. Thank you though. – Zimou Zhang Dec 28 '16 at 16:25
• arg in combination with (interactive "p") provides the cursor's point just like (point), as far as I know. – bertfred Dec 28 '16 at 19:10

I solved this problem:

(defun my-select-fun ()
(interactive)
(setq myline (line-number-at-pos))
(beginning-of-defun)
(set-mark (point))
(goto-line myline)
)


It sounds like all you really want is to select the defun that is around point. C-M-h (command mark-defun) does that.
If you really want to return to the original position then just write a command that binds a variable to (point) at the outset, then calls mark-defun, then uses goto-char to return to the position saved in that variable. To prevent the region from becoming deactivated after using your command, end it with (setq deactivate-mark nil).