smartparens
smartparens copied to clipboard
sp-kill-hybrid-sexp leaves untrimmed spaces when indent-tabs-mode is t
If I have something like
|function foo() {
// do something
}
After running sp-kill-hybrid-sexp, the tabs before foo are replaced by spaces.
When there's nothing there, presumably this whitespace ought to be trimmed, and smartparens should look at indent-tabs-mode and respect my indentation settings.
Hi.
I'm not sure I completely understand. The desired output is empty line, or point offset by a tab? In either case, it should probably respect tabs if you set that.
I think the desired output is offset by a tab, but others may disagree. The real issue is that existing tabs are converted to spaces.
but others may disagree
I'm not sure of a use case wherein one wants spaces while indent-tabs-mode is t - is there some?
I'm unskilled with cask - and unsure if this needs a test for the PR - a simple fix seems to be leave the spaces at the line-beginning untouched, and kill only from (point):
(defun sp-kill-hybrid-sexp (arg)
"Kill a line as if with `kill-line', but respecting delimiters.
With ARG being raw prefix \\[universal-argument] \\[universal-argument], kill the hybrid sexp
the point is in (see `sp-get-hybrid-sexp').
With ARG numeric prefix 0 (zero) just call `kill-line'.
You can customize the behaviour of this command by toggling
`sp-hybrid-kill-excessive-whitespace'.
Examples:
foo | bar baz -> foo | ;; nil
foo (bar | baz) quux -> foo (bar |) quux ;; nil
foo | bar (baz -> foo | ;; nil
quux)
foo \"bar |baz quux\" quack -> foo \"bar |\" quack ;; nil
foo (bar
baz) qu|ux (quack -> foo | hoo ;; \\[universal-argument] \\[universal-argument]
zaq) hoo
foo | (bar -> foo | ;; C-0
baz) baz)"
(interactive "P")
(let* ((raw (sp--raw-argument-p arg))
(arg (prefix-numeric-value arg))
(orig-indent (save-excursion
(back-to-indentation)
(current-column)))
(orig-column (current-column)))
(cond
((= arg 0) (kill-line))
((and raw (= arg 16))
(let ((hl (sp-get-hybrid-sexp)))
(sp-get hl (kill-region :beg-prf :end-suf))))
(t
(let ((hl (sp-get-hybrid-sexp)))
(save-excursion
(when (and (or (eq sp-hybrid-kill-entire-symbol t)
(and (functionp sp-hybrid-kill-entire-symbol)
(not (funcall sp-hybrid-kill-entire-symbol))))
(sp-point-in-symbol))
(sp-backward-sexp))
(sp-get hl
(let ((end (min (point-max) (if (looking-at "[ \t]*$")
(1+ :end-suf)
:end-suf))))
(when sp-hybrid-kill-excessive-whitespace
(save-excursion
(goto-char end)
(skip-chars-forward "\n\t\r\s")
(cond
((eq 'kill sp-hybrid-kill-excessive-whitespace)
(setq end (point)))
(t (delete-region end (point))))))
(kill-region (point) end)))))
(sp--cleanup-after-kill)
;; if we've killed the entire line, do *not* contract the indent
;; to just one space
(when (sp-point-in-blank-line)
;; <----------------------------- Changes this point forward ------------------------------------>
(delete-region (point) (line-end-position))
(if (and (= 0 orig-column)
kill-whole-line)
;; delete the newline
(delete-char 1)))))))