Note that I use spaces for tabs. When I am working in erb files for rails such as example.js.erb or example2.html.erb, I am getting some very odd (and annoying) auto-tabbing behaviour, which I can't figure out.

For example, in a js.erb file I'll type:

function blaah(){  //a comment
  var a = 5;

Then I'll press tab on each line and I'll get

function blaah(){  //a comment
                   var a = 5;

It would appear as though the 2nd line is attempting to align with the comment above, but for what reason I do not know.

Here is my .emacs file:

(require 'package)
(add-to-list 'package-archives
         '("melpa" . "http://melpa.milkbox.net/packages/")

(load-theme 'misterioso)
(setq inhibit-splash-screen t)

; remove tool/scroll bars
(tool-bar-mode -1)
(scroll-bar-mode -1)

; (row,column) shown in bottom bar
(column-number-mode 1)

; line numbers on the left
(global-linum-mode 1)

; highlight current line num
(require 'hlinum)
(setq hl-line-sticky-flag nil)

(require 'smartparens)
(smartparens-global-mode t)
(require 'smartparens-config)
(sp-pair "%" "%" :wrap "C-%")

(add-to-list 'load-path "c:/Users/darre00/AppData/Roaming/.emacs.d/web-mode-master")
(require 'web-mode)
(add-to-list 'auto-mode-alist '("\\.phtml\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.tpl\\.php\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.[agj]sp\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.as[cp]x\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.erb\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.mustache\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.djhtml\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))
(setq web-mode-enable-auto-pairing nil)

(require 'json-mode)
(add-hook 'json-mode-hook 'hs-minor-mode)

(require 'org)
;; Make org-mode activate automatically for files ending in .org
(add-to-list 'auto-mode-alist '("\\.org$" . org-mode))

(require 'multiple-cursors)
(global-set-key (kbd "C-S-c C-S-c") 'mc/edit-lines)
(global-set-key (kbd "C->") 'mc/mark-next-like-this)
(global-set-key (kbd "C-<") 'mc/mark-previous-like-this)
(global-set-key (kbd "C-c C-<") 'mc/mark-all-like-this)

(require 'expand-region)
(global-set-key (kbd "C-=") 'er/expand-region)
(global-set-key (kbd "C-+") 'er/contract-region)

; scrolling starts 2 lines away from top/bottom
(setq scroll-margin 2
      scroll-preserve-screen-position 1)

; indentation
(setq-default c-basic-offset 2)
(setq-default js-indent-level 2)
(setq-default indent-tabs-mode nil)
(setq-default tab-width 2)
(setq-default web-mode-code-indent-offset 2)

; full file path in title bar
(setq-default frame-title-format '((:eval (if (buffer-file-name)
                                              (abbreviate-file-name (buffer-file-name)) "%f"))))

(ido-mode 1)

(defun kill-dired-buffers()
  "Kill all dired buffers open."
  (mapc (lambda (buffer)
      (when (eq 'dired-mode (buffer-local-value 'major-mode buffer))
        (kill-buffer buffer)))
  (message "Killed all dired buffers")

(defun toggle-comment ()
  "comment or uncomment region or line"
  (let (beg end)
    (if (region-active-p)
        (setq beg (region-beginning) end (region-end))
      (setq beg (line-beginning-position) end (line-end-position)))
    (comment-or-uncomment-region beg end)))

(global-set-key (kbd "C-c k") 'kill-dired-buffers)
(global-set-key (kbd "C-c /") 'toggle-comment)

Any help is much appreciated.

  • Please do not post your entire init file, as much of it is not relevant to the question. Your best option is to sequentially bisect your init file until you isolate the problem. – Dan Nov 17 '15 at 18:27
  • Report an issue on github – fxbois Nov 17 '15 at 18:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.