Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs go to the beginning of line, skipping indentation

Tags:

emacs

I have a line of code in emacs:

<tab><tab>int i = 0;<cursor>

If I click Ctrl-a, it will move to the beginning of line:

<cursor><tab><tab>int i = 0;

But I want to create an elisp function, that will ignore any indentation at the beginning:

<tab><tab><cursor>int i = 0;

How to do that?

like image 503
user4035 Avatar asked Dec 06 '22 12:12

user4035


2 Answers

M-m runs the command back-to-indentation, which is an interactive compiled Lisp function in `simple.el'.

It is bound to M-m.

(back-to-indentation)

Move point to the first non-whitespace character on this line.

like image 138
freestyler Avatar answered Feb 18 '23 09:02

freestyler


(defun beginning-of-line++ ()
  (interactive)
  (if (bolp)
      (back-to-indentation)
    (beginning-of-line)))
(global-set-key (kbd "C-a") 'beginning-of-line++)

Then, If you click C-a, the cursor will move to the beginning of line, then click C-a again, the cursor will go back to indentation. The successive C-a will toggle replace the cursor between beginning of line and indentaion.

like image 36
hbin Avatar answered Feb 18 '23 09:02

hbin