Tabs vs. Spaces, VIM vs. EMACS (Was Re: Larry Wall's comment on python...)

Mark McEahern marklists at mceahern.com
Thu Sep 26 10:10:56 EDT 2002


[Chris Gonnerman]
> Surely emacs can do as well as VIM...  (and I expect a rabid
> emacs user to fill me in posthaste).

Yup.  Here are the relevant portions of my .emacs file:

;; Turn tabs off by default.
(setq-default intend-tabs-mode nil)

;; Set tab width to 4 by default.
(setq-default tab-width 4)

;; Use Python mode for .py files.
(setq auto-mode-alist
      (cons '("\\.py$" . python-mode)
            auto-mode-alist))

(setq interpreter-mode-alist
      (cons '("python" . python-mode)
            interpreter-mode-alist))

;; Load Python mode.
(autoload 'python-mode "python-mode" "Python editing mode." t)

;; Set up initialization parameters for python mode:
(setq python-mode-hook
      '(lambda () (progn
                    (set-variable 'py-indent-offset 4)
                    (set-variable 'py-smart-indentation nil)
                    (set-variable 'indent-tabs-mode nil) )))

;; Define untabify-buffer.
(defun untabify-buffer()
  (interactive)
  "Untabify the current buffer.  Return nil.

  Must return nil, if added to write-file-hooks."
  (save-excursion
    (goto-char (point-min))
    (while (re-search-forward "[ \t]+$" nil t)
      (delete-region (match-beginning 0) (match-end 0)))
    (goto-char (point-min))
    (if (search-forward "\t" nil t)
        (untabify (1- (point)) (point-max))))
  nil)

;; Untabify buffers on write file.
(defun do-on-write-file()
  (untabify-buffer))

;; Add the hook.
(add-hook 'write-file-hooks 'do-on-write-file)

// m




More information about the Python-list mailing list