Skip to content

Can not get sh-mode working with smart-tabs-mode #11

baby-gnu opened this Issue Aug 3, 2012 · 5 comments

2 participants

baby-gnu commented Aug 3, 2012


I tried to get sh mode working with the following:

(add-hook 'sh-mode-hook (lambda ()
                          (smart-tabs-advice sh-indent-line sh-indentation)))

But it does not work, is there a way to debug this?



I’d ask @jacius, who wrote that part of the code.



Any news on this request?


Sorry; no.

Does your #15 patch help at all with this?


No, #15 permit to ease the setup for users.

I just find the answer, use sh-basic-offset instead of sh-indentation, with a condition, if I do the following:

(add-hook 'sh-mode-hook
      (lambda ()
        (smart-tabs-advice sh-indent-line sh-basic-offset)

Then I create a buffer and run sh-script-mode(), I got:

Debugger entered--Lisp error: (error "Don't know how to make a localized variable an alias")
  defvaralias(sh-basic-offset tab-width)
  (progn (defvaralias (quote sh-basic-offset) (quote tab-width)) (defadvice sh-indent-line (around smart-tabs activate) (cond (smart-tabs-mode (save-excursion (beginning-of-line) (while (looking-at " *\\( +\\)   +") (replace-match "" nil nil nil 1))) (setq tab-width tab-width) (let ((indent-tabs-mode t) (tab-width fill-column) (sh-basic-offset fill-column)) (unwind-protect (progn ad-do-it)))) (t ad-do-it))))
  (smart-tabs-advice sh-indent-line sh-basic-offset)
  (lambda nil (smart-tabs-mode-enable) (smart-tabs-advice sh-indent-line sh-basic-offset))()
  run-hooks(change-major-mode-after-body-hook prog-mode-hook sh-mode-hook)
  apply(run-hooks (change-major-mode-after-body-hook prog-mode-hook sh-mode-hook))
  call-interactively(shell-script-mode record nil)
  command-execute(shell-script-mode record)
  execute-extended-command(nil "shell-script-mode")
  call-interactively(execute-extended-command nil nil)

The solution seems to be:

(setq sh-make-vars-local nil)

(add-hook 'sh-mode-hook
      (lambda ()
        (smart-tabs-advice sh-indent-line sh-basic-offset)

I thought about applying the following patch:

diff --git a/smart-tabs-mode.el b/smart-tabs-mode.el
index b2d0968..87e1529 100644
--- a/smart-tabs-mode.el
+++ b/smart-tabs-mode.el
@@ -138,6 +141,13 @@
                         (lambda ()
                           (smart-tabs-advice nxml-indent-line nxml-child-indent)))))
+    (sh-script . (lambda ()
+          (setq sh-make-vars-local nil)
+          (add-hook 'sh-mode-hook
+                (lambda ()
+                  (smart-tabs-mode-enable)
+                  (smart-tabs-advice sh-indent-line sh-basic-offset)
+                  ))))
   "Alist of language name and their activation code.
 Smarttabs is enabled in mode hook.")

But sh indentation seems too complex, with it, continuation lines are are indented with tabs instead of spaces :-/

test {
    echo "foo" \
        && echo "bar"
    echo "quux"

It seems you’re saying sh-mode indentation is too complex for smarttabs. I’m marking this issue Won’t fix and closing it; if someone offers working code we can revisit the issue. Sound good to you?

@jcsalomon jcsalomon closed this Nov 27, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.