You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"The distance between point at the time of insert and beginning of line.
This tracks the saved value of the last insertion so we can figure out whether
to indent for it.")
(defvar my-last-insertion-distance 0
"The distance between point at the time of insert and beginning of line.
This tracks the saved value of the last insertion so we can figure out whether
to indent for it.")
(defun my-sensible-to-indent-p ()
"Determine whether it's sensible to indent the current line automagically.
Using the data stored from my-exit-insert-state, this function determines
whether or not it makes sense to indent the following line. The point of this
is to ensure we don't indent lines after the user has manually tabbed point to
the beginning of a line, but we do indent lines if there was already an
indentation from the last insert state.
A potential future improvement is to (rather than blindly indenting according
to mode, which is a potshot) indent intelligently to the saved state of point."
(and (> my-last-insertion-distance 0)
(my-current-line-is-empty)))
(evil-define-motion my-append-and-indent (count)
"Moves to end of line, enters insert mode, and also indents the line."
(evil-append-line count)
(when (my-sensible-to-indent-p)
(indent-according-to-mode)))
(defun my-save-insert-state-state ()
"Save information about the state of insert state.
This does the following:
Sets my-last-insertion-end to the character position at the end of the last
insert state.
Sets my-last-insertion-line to the position at the beginning of the line from
the last insert state.
Sets my-last-insertion-distance to the distance between those two points.
Deletes trailing whitespace to the left of point.
The intent of this is to save the state of the insertion environment, so we can
make smart decisions based on it later."
(interactive)
(setq my-last-insertion-end
(save-excursion
(if (not (my-current-line-is-empty))
(beginning-of-line-text))
(point)))
(setq my-last-insertion-line
(save-excursion
(goto-char my-last-insertion-end)
(line-beginning-position)))
(setq my-last-insertion-distance
(- my-last-insertion-end my-last-insertion-line)))
(evil-define-motion my-ret-and-indent (count)
"Move the cursor COUNT lines down.
If point is on a widget or a button, click on it.
In Insert state, insert a newline and indent."
:type line
(my-save-insert-state-state)
(my-delete-trailing-whitespace-at-line)
(evil-ret-gen count nil)
(when (my-sensible-to-indent-p)
(indent-according-to-mode)))
(defun my-what-line ()
"Get the line, without printing the word 'line' before it."
(1+ (count-lines 1 (point))))
(defun my-where-beginning-of-visual-line ()
"Calculate the difference between the beginning
of the current visual line and point."
(interactive)
(let ((old-point (point))
(bovl (save-excursion (beginning-of-visual-line)
(point))))
(- old-point bovl)))
(defun my-current-line-is-empty ()
"Returns t when the current line is empty or contains only whitespace."
(interactive)
(save-excursion
(beginning-of-line)
(looking-at "^\s*$")))
(defun my-electric-append-with-indent (count &optional vcount)
"Indent the current line if it is empty.
Otherwise, just do a normal append-line."
(interactive "p")
(if (and (= (point) (line-beginning-position))
(my-is-this-line-empty))
(indent-according-to-mode))
(evil-append-line count vcount))
(defun my-exit-insert-state ()
"Function to be run when Evil exits insert state."
(my-save-insert-state-state)
(if (my-current-line-is-empty)
(delete-horizontal-space t)))
(defun my-enter-insert-state ()
"Function to be run when Evil enters insert state.
Loads indent data from my-sensible-to-indent-p and uses that to determine
whether to call indent-according-to-mode."
(interactive)
(if (my-sensible-to-indent-p)
(indent-according-to-mode)))
I dont know where is error ? even i cant not find the "g" in my-evil.el file
(use-package evil
:ensure evil
:config
(progn
"The distance between point at the time of insert and beginning of line.
This tracks the saved value of the last insertion so we can figure out whether
to indent for it.")
"The distance between point at the time of insert and beginning of line.
This tracks the saved value of the last insertion so we can figure out whether
to indent for it.")
Using the data stored from my-exit-insert-state, this function determines
whether or not it makes sense to indent the following line. The point of this
is to ensure we don't indent lines after the user has manually tabbed point to
the beginning of a line, but we do indent lines if there was already an
indentation from the last insert state.
A potential future improvement is to (rather than blindly indenting according
to mode, which is a potshot) indent intelligently to the saved state of point."
(and (> my-last-insertion-distance 0)
(my-current-line-is-empty)))
This does the following:
insert state.
the last insert state.
The intent of this is to save the state of the insertion environment, so we can
make smart decisions based on it later."
(interactive)
(setq my-last-insertion-end
(save-excursion
(if (not (my-current-line-is-empty))
(beginning-of-line-text))
(point)))
(setq my-last-insertion-line
(save-excursion
(goto-char my-last-insertion-end)
(line-beginning-position)))
(setq my-last-insertion-distance
(- my-last-insertion-end my-last-insertion-line)))
If point is on a widget or a button, click on it.
In Insert state, insert a newline and indent."
:type line
(my-save-insert-state-state)
(my-delete-trailing-whitespace-at-line)
(evil-ret-gen count nil)
(when (my-sensible-to-indent-p)
(indent-according-to-mode)))
of the current visual line and point."
(interactive)
(let ((old-point (point))
(bovl (save-excursion (beginning-of-visual-line)
(point))))
(- old-point bovl)))
Otherwise, just do a normal append-line."
(interactive "p")
(if (and (= (point) (line-beginning-position))
(my-is-this-line-empty))
(indent-according-to-mode))
(evil-append-line count vcount))
Loads indent data from my-sensible-to-indent-p and uses that to determine
whether to call indent-according-to-mode."
(interactive)
(if (my-sensible-to-indent-p)
(indent-according-to-mode)))
The text was updated successfully, but these errors were encountered: