Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 106 lines (97 sloc) 3.502 kb
8a09b473 » jacius
2011-09-29 Added smart-tabs-mode.el.
1 ;; Emacs smart tabs mode
2 ;; Intelligently indent with tabs, align with spaces!
3 ;;
24b6486d »
2011-11-09 Edit documentation
4 ;; To use, save smart-tabs-mode.el to a a directory on your load-path
5 ;; (e.g., ~/.emacs.d/elisp), then add the following to your .emacs file:
8a09b473 » jacius
2011-09-29 Added smart-tabs-mode.el.
6 ;;
7284a131 » alanpearce
2012-04-13 Change documentation to use autoload instead of require
7 ;; (autoload 'smart-tabs-mode "smart-tabs-mode"
8 ;; "Intelligently indent with tabs, align with spaces!")
9 ;; (autoload 'smart-tabs-mode-enable "smart-tabs-mode")
10 ;; (autoload 'smart-tabs-advice "smart-tabs-mode")
c0f7c829 »
2011-10-02 Document installation of smart-tabs-mode better
11 ;;
8a09b473 » jacius
2011-09-29 Added smart-tabs-mode.el.
12 ;; Then, for each language you want to use smart tabs, set up a hook
13 ;; and advice like so:
14 ;;
a2178003 » jacius
2011-10-02 Fixed documentation of smart-tabs-mode.el.
15 ;; (add-hook 'MODE-HOOK 'smart-tabs-mode-enable)
16 ;; (smart-tabs-advice INDENT-FUNC TAB-WIDTH-VAR)
8a09b473 » jacius
2011-09-29 Added smart-tabs-mode.el.
17 ;;
18 ;; Here are some specific examples for a few popular languages:
19 ;;
20 ;; ;; C/C++
21 ;; (add-hook 'c-mode-hook 'smart-tabs-mode-enable)
22 ;; (smart-tabs-advice c-indent-line c-basic-offset)
23 ;; (smart-tabs-advice c-indent-region c-basic-offset)
24 ;;
25 ;; ;; JavaScript
26 ;; (add-hook 'js2-mode-hook 'smart-tabs-mode-enable)
27 ;; (smart-tabs-advice js2-indent-line js2-basic-offset)
28 ;;
29 ;; ;; Perl (cperl-mode)
30 ;; (add-hook 'cperl-mode-hook 'smart-tabs-mode-enable)
31 ;; (smart-tabs-advice cperl-indent-line cperl-indent-level)
32 ;;
33 ;; ;; Python
34 ;; (add-hook 'python-mode-hook 'smart-tabs-mode-enable)
35 ;; (smart-tabs-advice python-indent-line-1 python-indent)
36 ;;
37 ;; ;; Ruby
38 ;; (add-hook 'ruby-mode-hook 'smart-tabs-mode-enable)
39 ;; (smart-tabs-advice ruby-indent-line ruby-indent-level)
40 ;;
41 ;;
42 ;; smart-tabs-mode.el is licensed under the GPLv2.
24b6486d »
2011-11-09 Edit documentation
43 ;; It is derived from <http://www.emacswiki.org/emacs/SmartTabs>
44 ;; as modified by John Croisant (jacius), along with Julien Fontanet and
45 ;; Tomita Hiroshi (tomykaira).
8a09b473 » jacius
2011-09-29 Added smart-tabs-mode.el.
46 ;;
24b6486d »
2011-11-09 Edit documentation
47 ;; Modification history is at <https://github.com/jcsalomon/smarttabs>.
8a09b473 » jacius
2011-09-29 Added smart-tabs-mode.el.
48
b21ee271 »
2011-11-08 Explicitly load Emacs advice
49 (require 'advice)
8a09b473 » jacius
2011-09-29 Added smart-tabs-mode.el.
50
51 (defmacro smart-tabs-mode/no-tabs-mode-advice (function)
52 `(unless (ad-find-advice ',function 'around 'smart-tabs)
53 (defadvice ,function (around smart-tabs activate)
54 (if smart-tabs-mode
55 (let ((indent-tabs-mode nil)) ad-do-it)
56 ad-do-it))))
57
6a4ee3ce » alanpearce
2012-04-06 Add autoload cookies to smart-tabs-mode.el
58 ;;;###autoload
8a09b473 » jacius
2011-09-29 Added smart-tabs-mode.el.
59 (define-minor-mode smart-tabs-mode
60 "Intelligently indent with tabs, align with spaces!"
61
62 (progn
63 (smart-tabs-mode/no-tabs-mode-advice align)
64 (smart-tabs-mode/no-tabs-mode-advice align-regexp)
65 (smart-tabs-mode/no-tabs-mode-advice indent-relative)
66
67 (unless
68 (ad-find-advice 'indent-according-to-mode 'around 'smart-tabs)
69 (defadvice indent-according-to-mode (around smart-tabs activate)
70 (if smart-tabs-mode
71 (let ((indent-tabs-mode indent-tabs-mode))
72 (if (memq indent-line-function
73 '(indent-relative
74 indent-relative-maybe))
75 (setq indent-tabs-mode nil))
76 ad-do-it)
77 ad-do-it)))
78 ))
79
6a4ee3ce » alanpearce
2012-04-06 Add autoload cookies to smart-tabs-mode.el
80 ;;;###autoload
8a09b473 » jacius
2011-09-29 Added smart-tabs-mode.el.
81 (defun smart-tabs-mode-enable ()
82 "Enable smart-tabs-mode."
83 (smart-tabs-mode t))
84
6a4ee3ce » alanpearce
2012-04-06 Add autoload cookies to smart-tabs-mode.el
85 ;;;###autoload
8a09b473 » jacius
2011-09-29 Added smart-tabs-mode.el.
86 (defmacro smart-tabs-advice (function offset)
87 `(progn
88 (defvaralias ',offset 'tab-width)
89 (defadvice ,function (around smart-tabs activate)
90 (cond
91 (smart-tabs-mode
92 (save-excursion
93 (beginning-of-line)
94 (while (looking-at "\t*\\( +\\)\t+")
95 (replace-match "" nil nil nil 1)))
96 (setq tab-width tab-width)
97 (let ((indent-tabs-mode t)
98 (tab-width fill-column)
99 (,offset fill-column))
100 (unwind-protect
101 (progn ad-do-it))))
102 (t
103 ad-do-it)))))
104
105
106 (provide 'smart-tabs-mode)
Something went wrong with that request. Please try again.