forked from colonelpanic/dotfiles
docstrings and various other tweaks for multi-line
This commit is contained in:
parent
03f4dabe6d
commit
598a299021
@ -24,10 +24,11 @@
|
|||||||
;;; Commentary:
|
;;; Commentary:
|
||||||
|
|
||||||
;; multi-line aims to provide a flexible framework for automatically
|
;; multi-line aims to provide a flexible framework for automatically
|
||||||
;; multi-lining and single-lining function invocations, array and map
|
;; multi-lining and single-lining function invocations and
|
||||||
;; literals and more. It relies on functions that are defined on a per
|
;; definitions, array and map literals and more. It relies on
|
||||||
;; major mode basis wherever it can so that function correctly across
|
;; functions that are defined on a per major mode basis wherever it
|
||||||
;; many different programming languages.
|
;; can so that it functions correctly across many different
|
||||||
|
;; programming languages.
|
||||||
|
|
||||||
;;; Code:
|
;;; Code:
|
||||||
|
|
||||||
@ -37,13 +38,15 @@
|
|||||||
(defvar multi-line-single-line-strategy)
|
(defvar multi-line-single-line-strategy)
|
||||||
|
|
||||||
(defun multi-line-lparenthesis-advance ()
|
(defun multi-line-lparenthesis-advance ()
|
||||||
|
"Advance to the beginning of a statement that can be multi-lined."
|
||||||
(re-search-forward "[[{(]"))
|
(re-search-forward "[[{(]"))
|
||||||
|
|
||||||
(defun multi-line-up-list-back ()
|
(defun multi-line-up-list-back ()
|
||||||
|
"Go to the beginning of a statement from inside the statement."
|
||||||
(up-list) (backward-sexp))
|
(up-list) (backward-sexp))
|
||||||
|
|
||||||
(defclass multi-line-forward-sexp-enter-strategy ()
|
(defclass multi-line-forward-sexp-enter-strategy ()
|
||||||
((done-regex :initarg :done-regex :initform "[[:space:]]*\[[({]")
|
((done-regex :initarg :done-regex :initform "[[:space:]]*[[({]")
|
||||||
(advance-fn :initarg :advance-fn :initform 'multi-line-lparenthesis-advance)
|
(advance-fn :initarg :advance-fn :initform 'multi-line-lparenthesis-advance)
|
||||||
(inside-fn :initarg :inside-fn :initform 'multi-line-up-list-back)))
|
(inside-fn :initarg :inside-fn :initform 'multi-line-up-list-back)))
|
||||||
|
|
||||||
@ -56,12 +59,9 @@
|
|||||||
(funcall (oref enter :advance-fn)))
|
(funcall (oref enter :advance-fn)))
|
||||||
|
|
||||||
(defun multi-line-comma-advance ()
|
(defun multi-line-comma-advance ()
|
||||||
|
"Advance to the next comma."
|
||||||
(re-search-forward ","))
|
(re-search-forward ","))
|
||||||
|
|
||||||
(defun multi-line-done-advance ()
|
|
||||||
(re-search-forward "[)}\]")
|
|
||||||
(backward-char))
|
|
||||||
|
|
||||||
(defclass multi-line-forward-sexp-find-strategy ()
|
(defclass multi-line-forward-sexp-find-strategy ()
|
||||||
((split-regex :initarg :split-regex :initform "[[:space:]]*,")
|
((split-regex :initarg :split-regex :initform "[[:space:]]*,")
|
||||||
(done-regex :initarg :done-regex :initform "[[:space:]]*[})]")
|
(done-regex :initarg :done-regex :initform "[[:space:]]*[})]")
|
||||||
@ -136,6 +136,10 @@
|
|||||||
(oref respacer :default-respacer)) index markers))
|
(oref respacer :default-respacer)) index markers))
|
||||||
|
|
||||||
(defun multi-line-get-markers (enter-strategy find-strategy)
|
(defun multi-line-get-markers (enter-strategy find-strategy)
|
||||||
|
"Get the markers for multi-line candidates for the statement at point.
|
||||||
|
|
||||||
|
ENTER-STRATEGY is a class with the method multi-line-enter, and
|
||||||
|
FIND-STRATEGY is a class with the method multi-line-find-next."
|
||||||
(multi-line-enter enter-strategy)
|
(multi-line-enter enter-strategy)
|
||||||
(let ((markers (list (point-marker))))
|
(let ((markers (list (point-marker))))
|
||||||
(nconc markers
|
(nconc markers
|
||||||
@ -144,13 +148,17 @@
|
|||||||
(nconc markers (list (point-marker)))))
|
(nconc markers (list (point-marker)))))
|
||||||
|
|
||||||
(defun multi-line-clear-whitespace-at-point ()
|
(defun multi-line-clear-whitespace-at-point ()
|
||||||
|
"Erase any surrounding whitespace."
|
||||||
(interactive)
|
(interactive)
|
||||||
|
(re-search-backward "[^[:space:]\n]")
|
||||||
|
(forward-char)
|
||||||
(let ((start (point)))
|
(let ((start (point)))
|
||||||
(re-search-forward "[^[:space:]\n]")
|
(re-search-forward "[^[:space:]\n]")
|
||||||
(backward-char)
|
(backward-char)
|
||||||
(kill-region start (point))))
|
(kill-region start (point))))
|
||||||
|
|
||||||
(defun multi-line-adjust-whitespace (respacer)
|
(defun multi-line-adjust-whitespace (respacer)
|
||||||
|
"Adjust whitespace using the provided RESPACER."
|
||||||
(let ((markers (multi-line-get-markers multi-line-enter-strategy
|
(let ((markers (multi-line-get-markers multi-line-enter-strategy
|
||||||
multi-line-find-strategy)))
|
multi-line-find-strategy)))
|
||||||
(cl-loop for marker being the elements of markers using (index i) do
|
(cl-loop for marker being the elements of markers using (index i) do
|
||||||
@ -160,6 +168,7 @@
|
|||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun multi-line-set-default-strategies ()
|
(defun multi-line-set-default-strategies ()
|
||||||
|
"Set multi-line strategies that work for languages with C-like syntax."
|
||||||
(interactive)
|
(interactive)
|
||||||
(setq multi-line-find-strategy
|
(setq multi-line-find-strategy
|
||||||
(make-instance multi-line-forward-sexp-find-strategy)
|
(make-instance multi-line-forward-sexp-find-strategy)
|
||||||
@ -172,11 +181,13 @@
|
|||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun multi-line-multiline ()
|
(defun multi-line-multiline ()
|
||||||
|
"Multi-line the statement at point."
|
||||||
(interactive)
|
(interactive)
|
||||||
(multi-line-adjust-whitespace multi-line-multi-line-strategy))
|
(multi-line-adjust-whitespace multi-line-multi-line-strategy))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun multi-line-singleline ()
|
(defun multi-line-singleline ()
|
||||||
|
"Single-line the statement at point."
|
||||||
(interactive)
|
(interactive)
|
||||||
(multi-line-adjust-whitespace multi-line-single-line-strategy))
|
(multi-line-adjust-whitespace multi-line-single-line-strategy))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user