Open spiderbit opened 7 years ago
Hacked something together which is far from perfect but some sort of proof-of-concept.
first I used only basic elisp expressions, but in the end I remembered the python specific functions and used that for change the indent. So it depends on python.el. But no matter if I use here expressions from python.el or not the code is so far python-specific and would not work in C-style code.
Some thoughts about it?
(defun sp-raise-hybrid-sexp (&optional arg)
(interactive "P")
(let* ((current (save-excursion
(sp-forward-sexp)
(sp-backward-sexp)
(sp-get-hybrid-sexp)))
(end (save-excursion
(goto-char (sp-get current :beg))
(let ((block-column (current-column)))
(while (>= (current-column) block-column)
(next-line)
(beginning-of-line)
(sp-forward-sexp)
(sp-backward-sexp)))
(sp-backward-sexp)
(sp-get-hybrid-sexp)))
(prev (save-excursion
(goto-char (sp-get current :beg))
(sp-backward-sexp)
(sp-get-hybrid-sexp))))
(if (sp-compare-sexps prev current > :end)
(sp-message :invalid-context-prev)
(sp-backward-sexp)
(python-indent-shift-left (sp-get current :beg) (sp-get end :end)))
(delete-region (sp-get prev :beg)(sp-get current :beg))
(when (looking-at "[\n\t ]+")
(forward-line)
(back-to-indentation))))
maybe the name sp-raise-block would be better not shure if hybrid-sexp is the right scope/name.
in lisp I use just normal sp-raise-sexp like that:
(if (equl a 1) |(print "2")
sp-raise-sexp I get:(print "2")
In Python that does not work cause the if statement is a hybrit-sexpr, so I want it to behave similar:
sp-raise-hybrid-sexp
print ("2")