jcsalomon / smarttabs

Emacs smart tabs - indent with tabs, align with spaces!
http://www.emacswiki.org/emacs/SmartTabs
114 stars 20 forks source link

Don't know how to make a localized variable an alias #19

Closed dkozdoba closed 11 years ago

dkozdoba commented 11 years ago

After installing smarttabs and trying to use it with c-mode on Windows Emacs I'm getting this error every time I'm opening C file:

File mode specification error: (error "Don't know how to make a localized variable an alias").

And smarttabs doesn't seem to be working.

The Emacs version I'm using is: GNU Emacs 24.1.1 (i386-mingw-nt6.1.7601) of 2012-06-10 on MARVIN.

I've seen this problem mentioned on stackoverflow.com as well as in this comment for bug #18 and in #11. But I can't find any solution for it.

ckoch786 commented 11 years ago

I have also observed this bug in GNU Emacs 24.3.1 on GNU/Linux, with Version: 20121202.1829.

m-renaud commented 11 years ago

Same here with GNU Emacs 24.3.1. The error is coming from the defvaralias because it makes no sense to bind at the point of time that the macro is expanded to the variable c-basic-offset since it will only be local to the C/C++/etc. file that will eventually be using smart-tabs-mode, so it has no meaning in the config file where the code is actually run.

I removed/replaced a few lines in the function and it appears to work correctly now, the author will have to take a look to see if I removed anything that will break something somewhere else, I didn't have time to explore the source in depth. Use this macro instead:

(defmacro smart-tabs-advice (function offset)
  `(progn
     (defadvice ,function (around smart-tabs activate)
       (cond
        (indent-tabs-mode
         (save-excursion
           (beginning-of-line)
           (while (looking-at "\t*\\( +\\)\t+")
             (replace-match "" nil nil nil 1)))
         (let ((tab-width fill-column)
               (,offset fill-column)
               (wstart (window-start)))
           (unwind-protect
               (progn ad-do-it)
             (set-window-start (selected-window) wstart))))
        (t
         ad-do-it)))))

Also, if you have whitespace-cleanup in your before-save-hook, make sure you customize whitespace-style and remove indentation-spaces from the list or else it will convert everything back to spaces before you save anyways :P

Edit: Also, you have to disable 'SPACEs after TAB' as well.

Hope that helps :)

jcsalomon commented 11 years ago

@mrenaud92, would you care to contribute this change as a pull-request?

m-renaud commented 11 years ago

@jcsalomon, sure, I won't be able to do it until later tonight though.

m-renaud commented 11 years ago

@jcsalomon, Also, it appears that the EmacsWiki page for SmartTabs (http://www.emacswiki.org/SmartTabs) is slightly out of date. In addition, the latest version on Melpa is 20130317.1157. After the pull request, we/I/someone should update the Wikipage, the README and the Melpa entry, sound good?

arianitu commented 11 years ago

I just pulled from Melpa and had this issue. Glad it was fixed, and only 15 minutes ago!