Refactor editor autoloaded library
And remove doom/toggle-sticky; this has been replaced with scratch buffers.
This commit is contained in:
parent
c7d63fe091
commit
311e15487a
1 changed files with 62 additions and 64 deletions
|
@ -15,21 +15,19 @@
|
||||||
(interactive)
|
(interactive)
|
||||||
(doom/sudo-find-file (file-truename buffer-file-name)))
|
(doom/sudo-find-file (file-truename buffer-file-name)))
|
||||||
|
|
||||||
(defun doom--goto-first-non-blank ()
|
|
||||||
(beginning-of-visual-line)
|
|
||||||
(skip-chars-forward " \t\r"))
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom/backward-to-bol-or-indent ()
|
(defun doom/backward-to-bol-or-indent ()
|
||||||
"Move back to the current line's indentation. If already there, move to the
|
"Move back to the current line's indentation. If already there, move to the
|
||||||
beginning of the line instead. If at bol, do nothing."
|
beginning of the line instead. If at bol, do nothing."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let ((boi (save-excursion (back-to-indentation) (point)))
|
(if (bound-and-true-p visual-line-mode)
|
||||||
(point (point)))
|
(beginning-of-visual-line)
|
||||||
(if (= boi point)
|
(let ((ci (current-indentation))
|
||||||
(beginning-of-visual-line)
|
(cc (current-column)))
|
||||||
(unless (= (line-beginning-position) point)
|
(cond ((or (> cc ci) (= cc 0))
|
||||||
(doom--goto-first-non-blank)))))
|
(back-to-indentation))
|
||||||
|
((<= cc ci)
|
||||||
|
(beginning-of-visual-line))))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom/forward-to-last-non-comment-or-eol ()
|
(defun doom/forward-to-last-non-comment-or-eol ()
|
||||||
|
@ -80,22 +78,28 @@ If already there, do nothing."
|
||||||
(interactive)
|
(interactive)
|
||||||
(if indent-tabs-mode
|
(if indent-tabs-mode
|
||||||
(call-interactively #'backward-delete-char)
|
(call-interactively #'backward-delete-char)
|
||||||
(save-excursion
|
(unless (bolp)
|
||||||
(unless (looking-back "^[\s\t]*" (line-beginning-position))
|
(save-excursion
|
||||||
(doom--goto-first-non-blank))
|
(when (> (current-column) (current-indentation))
|
||||||
(let* ((movement (% (current-column) tab-width))
|
(back-to-indentation))
|
||||||
(spaces (if (= 0 movement) tab-width (- tab-width movement))))
|
(let ((movement (% (current-column) tab-width)))
|
||||||
(delete-char (- spaces))))))
|
(delete-char
|
||||||
|
(- (if (= 0 movement)
|
||||||
|
tab-width
|
||||||
|
(- tab-width movement)))))))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom/backward-kill-to-bol-and-indent ()
|
(defun doom/backward-kill-to-bol-and-indent ()
|
||||||
"Kill line to the first non-blank character. If invoked again
|
"Kill line to the first non-blank character. If invoked again
|
||||||
afterwards, kill line to column 1."
|
afterwards, kill line to column 1."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let ((empty-line (save-excursion (beginning-of-line) (looking-at-p "[ \t]*$"))))
|
(let ((empty-line-p (save-excursion (beginning-of-line)
|
||||||
(funcall (if (featurep 'evil) #'evil-delete #'delete-region)
|
(looking-at-p "[ \t]*$"))))
|
||||||
|
(funcall (if (featurep 'evil)
|
||||||
|
#'evil-delete
|
||||||
|
#'delete-region)
|
||||||
(point-at-bol) (point))
|
(point-at-bol) (point))
|
||||||
(unless empty-line
|
(unless empty-line-p
|
||||||
(indent-according-to-mode))))
|
(indent-according-to-mode))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
|
@ -131,7 +135,9 @@ possible, or just one char if that's not possible."
|
||||||
(save-match-data
|
(save-match-data
|
||||||
(if (string-match "\\w*\\(\\s-+\\)$"
|
(if (string-match "\\w*\\(\\s-+\\)$"
|
||||||
(buffer-substring-no-properties (max (point-min) (- p movement)) p))
|
(buffer-substring-no-properties (max (point-min) (- p movement)) p))
|
||||||
(sp-delete-char (- 0 (- (match-end 1) (match-beginning 1))))
|
(sp-delete-char
|
||||||
|
(- 0 (- (match-end 1)
|
||||||
|
(match-beginning 1))))
|
||||||
(call-interactively delete-backward-char)))))
|
(call-interactively delete-backward-char)))))
|
||||||
|
|
||||||
;; Otherwise do a regular delete
|
;; Otherwise do a regular delete
|
||||||
|
@ -157,18 +163,19 @@ spaces on either side of the point if so. Resorts to
|
||||||
`doom/backward-delete-whitespace-to-column' otherwise."
|
`doom/backward-delete-whitespace-to-column' otherwise."
|
||||||
(interactive)
|
(interactive)
|
||||||
(save-match-data
|
(save-match-data
|
||||||
(cond ((doom--surrounded-p)
|
(if (doom--surrounded-p)
|
||||||
(let ((whitespace-match (match-string 1)))
|
(let ((whitespace-match (match-string 1)))
|
||||||
(cond ((not whitespace-match)
|
(cond ((not whitespace-match)
|
||||||
(call-interactively #'delete-backward-char))
|
(call-interactively #'delete-backward-char))
|
||||||
((string-match "\n" whitespace-match)
|
((string-match "\n" whitespace-match)
|
||||||
(funcall (if (featurep 'evil) #'evil-delete #'delete-region)
|
(funcall (if (featurep 'evil)
|
||||||
(point-at-bol) (point))
|
#'evil-delete
|
||||||
(call-interactively #'delete-backward-char)
|
#'delete-region)
|
||||||
(save-excursion (call-interactively #'delete-char)))
|
(point-at-bol) (point))
|
||||||
(t (just-one-space 0)))))
|
(call-interactively #'delete-backward-char)
|
||||||
(t
|
(save-excursion (call-interactively #'delete-char)))
|
||||||
(doom/backward-delete-whitespace-to-column)))))
|
(t (just-one-space 0))))
|
||||||
|
(doom/backward-delete-whitespace-to-column))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom/newline-and-indent ()
|
(defun doom/newline-and-indent ()
|
||||||
|
@ -179,21 +186,22 @@ with weak native support."
|
||||||
(cond ((sp-point-in-string)
|
(cond ((sp-point-in-string)
|
||||||
(newline))
|
(newline))
|
||||||
((sp-point-in-comment)
|
((sp-point-in-comment)
|
||||||
(cond ((memq major-mode '(js2-mode rjsx-mode))
|
(pcase major-mode
|
||||||
(call-interactively #'js2-line-break))
|
((or 'js2-mode 'rjsx-mode)
|
||||||
((memq major-mode '(java-mode php-mode))
|
(call-interactively #'js2-line-break))
|
||||||
(c-indent-new-comment-line))
|
((or 'java-mode 'php-mode)
|
||||||
((memq major-mode '(c-mode c++-mode objc-mode css-mode scss-mode js2-mode))
|
(c-indent-new-comment-line))
|
||||||
(newline-and-indent)
|
((or 'c-mode 'c++-mode 'objc-mode 'css-mode 'scss-mode 'js2-mode)
|
||||||
(insert "* ")
|
(newline-and-indent)
|
||||||
(indent-according-to-mode))
|
(insert "* ")
|
||||||
(t
|
(indent-according-to-mode))
|
||||||
;; Fix an off-by-one cursor-positioning issue
|
(_
|
||||||
;; with `indent-new-comment-line'
|
;; Fix an off-by-one cursor-positioning issue
|
||||||
(let ((col (save-excursion (comment-beginning) (current-column))))
|
;; with `indent-new-comment-line'
|
||||||
(indent-new-comment-line)
|
(let ((col (save-excursion (comment-beginning) (current-column))))
|
||||||
(unless (= col (current-column))
|
(indent-new-comment-line)
|
||||||
(insert " "))))))
|
(unless (= col (current-column))
|
||||||
|
(insert " "))))))
|
||||||
(t
|
(t
|
||||||
(newline nil t)
|
(newline nil t)
|
||||||
(indent-according-to-mode))))
|
(indent-according-to-mode))))
|
||||||
|
@ -210,22 +218,9 @@ consistent throughout a selected region, depending on `indent-tab-mode'."
|
||||||
(tabify beg end)
|
(tabify beg end)
|
||||||
(untabify beg end)))
|
(untabify beg end)))
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/toggle-sticky (&optional beg end)
|
|
||||||
"Make a selection sticky by placing it in the header line. Possibly helpful
|
|
||||||
for function signatures or notes. Run again to clear the header line."
|
|
||||||
(interactive "r")
|
|
||||||
(setq header-line-format
|
|
||||||
(when mark-active
|
|
||||||
(concat (propertize (format linum-format (line-number-at-pos beg))
|
|
||||||
'face 'font-lock-comment-face)
|
|
||||||
(let ((content (buffer-substring beg end)))
|
|
||||||
(setq content (replace-regexp-in-string "\n" " " content t t))
|
|
||||||
(setq content (replace-regexp-in-string "\\s-+" " " content))
|
|
||||||
content)))))
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom|enable-delete-trailing-whitespace ()
|
(defun doom|enable-delete-trailing-whitespace ()
|
||||||
|
"Attaches `delete-trailing-whitespace' to a buffer-local `before-save-hook'."
|
||||||
(add-hook 'before-save-hook #'delete-trailing-whitespace nil t))
|
(add-hook 'before-save-hook #'delete-trailing-whitespace nil t))
|
||||||
|
|
||||||
|
|
||||||
|
@ -249,9 +244,12 @@ for function signatures or notes. Run again to clear the header line."
|
||||||
(mkdir doom-scratch-files-dir t))
|
(mkdir doom-scratch-files-dir t))
|
||||||
(with-current-buffer
|
(with-current-buffer
|
||||||
(if project-p
|
(if project-p
|
||||||
(find-file-noselect (expand-file-name (replace-regexp-in-string "\\." "_" (projectile-project-name) t t)
|
(find-file-noselect
|
||||||
doom-scratch-files-dir)
|
(expand-file-name (replace-regexp-in-string
|
||||||
nil t)
|
"\\." "_" (projectile-project-name)
|
||||||
|
t t)
|
||||||
|
doom-scratch-files-dir)
|
||||||
|
nil t)
|
||||||
(get-buffer-create "*doom:scratch*"))
|
(get-buffer-create "*doom:scratch*"))
|
||||||
(when project-p
|
(when project-p
|
||||||
(rename-buffer (format "*doom:scratch (%s)*" (projectile-project-name))))
|
(rename-buffer (format "*doom:scratch (%s)*" (projectile-project-name))))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue