Rewrote initfiles; bugfixes galore
This commit is contained in:
parent
02863ee529
commit
d5f2bb1d23
9 changed files with 288 additions and 45 deletions
198
elisp/ruby-mode-indent-fix.el
Normal file
198
elisp/ruby-mode-indent-fix.el
Normal file
|
@ -0,0 +1,198 @@
|
||||||
|
;;; ruby-mode-indent-fix.el ---
|
||||||
|
|
||||||
|
;; this file is not part of Emacs
|
||||||
|
|
||||||
|
;; Copyright (C) 2012 Le Wang
|
||||||
|
;; Author: Le Wang
|
||||||
|
;; Maintainer: Le Wang
|
||||||
|
;; Description:
|
||||||
|
;; Author: Le Wang
|
||||||
|
;; Maintainer: Le Wang
|
||||||
|
|
||||||
|
;; Created: Sun Feb 26 23:27:17 2012 (+0800)
|
||||||
|
;; Version: 0.1
|
||||||
|
;; Last-Updated: Mon Mar 26 11:23:48 2012 (+0800)
|
||||||
|
;; By: Le Wang
|
||||||
|
;; Update #: 29
|
||||||
|
;; URL:
|
||||||
|
;; Keywords:
|
||||||
|
;; Compatibility:
|
||||||
|
|
||||||
|
;;; Installation:
|
||||||
|
|
||||||
|
;; (eval-after-load "ruby-mod" '(require 'ruby-mode-indent-fix))
|
||||||
|
;;
|
||||||
|
;;
|
||||||
|
|
||||||
|
;;; Commentary:
|
||||||
|
|
||||||
|
;; Fix some indentation issues with ruby-mode with advices.
|
||||||
|
;;
|
||||||
|
;; Based on work by Dmitry Gutov(dgutov)
|
||||||
|
;; - http://stackoverflow.com/a/7622971/903943 and
|
||||||
|
;; - https://gist.github.com/1274520
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;;
|
||||||
|
;; This program is free software; you can redistribute it and/or
|
||||||
|
;; modify it under the terms of the GNU General Public License as
|
||||||
|
;; published by the Free Software Foundation; either version 3, or
|
||||||
|
;; (at your option) any later version.
|
||||||
|
;;
|
||||||
|
;; This program is distributed in the hope that it will be useful,
|
||||||
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
;; General Public License for more details.
|
||||||
|
;;
|
||||||
|
;; You should have received a copy of the GNU General Public License
|
||||||
|
;; along with this program; see the file COPYING. If not, write to
|
||||||
|
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
|
||||||
|
;; Floor, Boston, MA 02110-1301, USA.
|
||||||
|
;;
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
;;; Code:
|
||||||
|
|
||||||
|
(eval-when-compile (require 'cl))
|
||||||
|
|
||||||
|
(provide 'ruby-mode-indent-fix)
|
||||||
|
(require 'autopair)
|
||||||
|
|
||||||
|
|
||||||
|
(defvar ruby--paren-closings-regex
|
||||||
|
"[])}\"']"
|
||||||
|
"regex matching closing paren or string delimiter.")
|
||||||
|
|
||||||
|
;; We make this advice around to avoid unnecessary buffer modifications.
|
||||||
|
|
||||||
|
(defadvice ruby-indent-line (around fix-closing-paren activate)
|
||||||
|
"indent closing paren to line up properly.
|
||||||
|
|
||||||
|
i.e.
|
||||||
|
|
||||||
|
foo_function( {:a => 'foo',
|
||||||
|
:b => 'bar'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
Note that the closing paren is vertically aligned with the opening paren.
|
||||||
|
|
||||||
|
note: `ruby-deep-indent-paren' has to be enabled for this to work."
|
||||||
|
(let ((column (current-column))
|
||||||
|
indent)
|
||||||
|
(when ruby-deep-indent-paren
|
||||||
|
(save-excursion
|
||||||
|
(back-to-indentation)
|
||||||
|
(let ((state (syntax-ppss)))
|
||||||
|
(when (and (or (memq (autopair-find-pair (char-after)) ruby-deep-indent-paren)
|
||||||
|
(and (eq (char-after) ?\})
|
||||||
|
(eq 'brace (ruby--point-in-braced-proc))))
|
||||||
|
(not (zerop (car state))))
|
||||||
|
(goto-char (cadr state))
|
||||||
|
(setq indent (current-column))))))
|
||||||
|
(if indent
|
||||||
|
(indent-line-to indent)
|
||||||
|
ad-do-it)))
|
||||||
|
|
||||||
|
(defun ruby--indent-before-all-sexps ()
|
||||||
|
"
|
||||||
|
1. search backwards for a closing delimiter ON THIS LINE, then
|
||||||
|
find the matching opening
|
||||||
|
|
||||||
|
2. if found, recurse, else the point is at a place we don't need
|
||||||
|
to worry about sexps.
|
||||||
|
"
|
||||||
|
(if (re-search-backward ruby--paren-closings-regex (point-at-bol) t)
|
||||||
|
(let ((ppss (syntax-ppss))
|
||||||
|
beg)
|
||||||
|
(goto-char (match-beginning 0))
|
||||||
|
(cond ((setq beg (nth 1 ppss)) ; brace
|
||||||
|
(goto-char beg))
|
||||||
|
((nth 3 ppss) ; string
|
||||||
|
(goto-char (nth 8 ppss))))
|
||||||
|
(ruby--indent-before-all-sexps))))
|
||||||
|
|
||||||
|
(defun ruby--point-in-braced-proc ()
|
||||||
|
"returns 'proc if point is in braces where starting bracs is EOL or followed by arg-list
|
||||||
|
|
||||||
|
i.e.
|
||||||
|
|
||||||
|
arr.each { |foo|
|
||||||
|
// do stuff
|
||||||
|
}
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
1.times {
|
||||||
|
// do stuff
|
||||||
|
}
|
||||||
|
returns 'brace if point in brace
|
||||||
|
|
||||||
|
return nil otherwise
|
||||||
|
"
|
||||||
|
(save-excursion
|
||||||
|
(let ((ppss (syntax-ppss))
|
||||||
|
beg)
|
||||||
|
(cond ((nth 3 ppss) ; string
|
||||||
|
nil)
|
||||||
|
((setq beg (nth 1 ppss)) ; brace
|
||||||
|
(goto-char beg)
|
||||||
|
(if (looking-at-p "{[\t ]*\\(?:$\\||\\)")
|
||||||
|
'proc
|
||||||
|
(when (looking-at-p "{")
|
||||||
|
'brace)))))))
|
||||||
|
|
||||||
|
(defadvice ruby-indent-line (around line-up-args activate)
|
||||||
|
"indent new line after comma at EOL properly:
|
||||||
|
|
||||||
|
i.e.
|
||||||
|
|
||||||
|
foo_function a_param,
|
||||||
|
b_param,
|
||||||
|
c_param
|
||||||
|
|
||||||
|
Note that all params line up after the function.
|
||||||
|
"
|
||||||
|
(let (indent ppss)
|
||||||
|
(save-excursion
|
||||||
|
(back-to-indentation)
|
||||||
|
(skip-chars-backward " \t\n")
|
||||||
|
(setq ppss (syntax-ppss))
|
||||||
|
;; check for inside comment, string, or inside braces
|
||||||
|
(when (and (eq ?, (char-before))
|
||||||
|
(not (memq (syntax-ppss-context ppss) '(comment string)))
|
||||||
|
(zerop (car ppss)))
|
||||||
|
(ruby--indent-before-all-sexps)
|
||||||
|
(back-to-indentation)
|
||||||
|
(if (save-excursion
|
||||||
|
(skip-chars-backward " \t\n")
|
||||||
|
(eq (char-before) ?,))
|
||||||
|
(setq indent (current-column))
|
||||||
|
(skip-syntax-forward "w_.")
|
||||||
|
(skip-chars-forward " ")
|
||||||
|
;; if the first symbol on the line is followed, by a comma, then this
|
||||||
|
;; line must be a continuation
|
||||||
|
(setq indent (current-column)))))
|
||||||
|
(if indent
|
||||||
|
(indent-line-to indent)
|
||||||
|
ad-do-it)))
|
||||||
|
|
||||||
|
;; (defadvice ruby-indent-line (around indent-no-brace-args activate)
|
||||||
|
;; "indent new line after comma at EOL properly:
|
||||||
|
|
||||||
|
;; i.e.
|
||||||
|
|
||||||
|
;; foo_function a_param,
|
||||||
|
;; b_param,
|
||||||
|
;; c_param
|
||||||
|
|
||||||
|
;; Note that all params line up after the function."
|
||||||
|
;; (let ((res (ruby--point-in-braced-proc)))
|
||||||
|
;; (cond ((eq 'brace res)
|
||||||
|
;; (let ((ruby-deep-indent-paren '(?\[ ?\( ?\{ t)))
|
||||||
|
;; ad-do-it))
|
||||||
|
;; (t
|
||||||
|
;; ad-do-it))))
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;;; ruby-mode-indent-fix.el ends here
|
2
init.el
2
init.el
|
@ -47,12 +47,12 @@
|
||||||
|
|
||||||
;; Modules to improve on emacs' heresy
|
;; Modules to improve on emacs' heresy
|
||||||
mod-ac ; Auto-complete engine & settings
|
mod-ac ; Auto-complete engine & settings
|
||||||
;; mod-shell ; Terminal emulator settings
|
|
||||||
mod-snippets ; Snippet engine
|
mod-snippets ; Snippet engine
|
||||||
mod-git ; GIT tools/settings
|
mod-git ; GIT tools/settings
|
||||||
mod-fly ; Syntax and spell checkers
|
mod-fly ; Syntax and spell checkers
|
||||||
; mod-webdev ; Webdev tools (sass, js, etc)
|
; mod-webdev ; Webdev tools (sass, js, etc)
|
||||||
; mod-gamedev ; Gamedev tools (C++, love2D, html5)
|
; mod-gamedev ; Gamedev tools (C++, love2D, html5)
|
||||||
|
; mod-shell ; Terminal emulator settings
|
||||||
|
|
||||||
;; Must be last
|
;; Must be last
|
||||||
core-keymaps ; Global & local keybindings for all modes
|
core-keymaps ; Global & local keybindings for all modes
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
(require-package 'evil)
|
(require-package 'evil)
|
||||||
(evil-mode nil)
|
|
||||||
|
|
||||||
;; Has to be done this way to ensure special buffers have evil,
|
;; Has to be done this way to ensure special buffers have evil,
|
||||||
;; evil-leader, and all the various keymaps enabled.
|
;; evil-leader, and all the various keymaps enabled.
|
||||||
|
(evil-mode nil)
|
||||||
(add-hook 'after-init-hook (lambda() (evil-mode 1)))
|
(add-hook 'after-init-hook (lambda() (evil-mode 1)))
|
||||||
|
|
||||||
;; Now we can carry on with the rest...
|
;; Now we can carry on with the rest...
|
||||||
|
@ -34,13 +34,13 @@
|
||||||
;;;; Editor behavior ;;;;;;;;;;;;;;;;
|
;;;; Editor behavior ;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(setq initial-scratch-buffer nil) ; empty scratch buffer
|
(setq initial-scratch-buffer nil) ; empty scratch buffer
|
||||||
(kill-buffer "*scratch*")
|
(associate-mode 'text-mode '("\\`\\*Messages\\*\\'") t)
|
||||||
|
|
||||||
(electric-indent-mode +1) ; auto-indent on RET
|
(electric-indent-mode +1) ; auto-indent on RET
|
||||||
(global-hl-line-mode +1) ; highlight the line
|
(global-hl-line-mode +1) ; highlight the line
|
||||||
(setq-default
|
(setq-default
|
||||||
tab-width 4 ; set tab width to 4 for all buffers
|
tab-width 4 ; set tab width to 4 for all buffers
|
||||||
indent-tabs-mode t ; always replace tabs with spaces
|
indent-tabs-mode t ; use tabs, not spaces
|
||||||
tab-always-indent nil)
|
tab-always-indent nil)
|
||||||
|
|
||||||
;; do not soft-wrap lines
|
;; do not soft-wrap lines
|
||||||
|
|
|
@ -72,11 +72,13 @@
|
||||||
";" 'helm-imenu
|
";" 'helm-imenu
|
||||||
"," 'ido-switch-buffer
|
"," 'ido-switch-buffer
|
||||||
"=" 'align-regexp
|
"=" 'align-regexp
|
||||||
"X" 'kill-other-buffers
|
"x" 'kill-other-buffers
|
||||||
|
"X" 'kill-all-buffers
|
||||||
)
|
)
|
||||||
|
|
||||||
(nmap
|
(nmap
|
||||||
";" 'evil-ex ; Remap ; to : - SPC and shift-SPC replace ; and ,
|
";" 'evil-ex ; Remap ; to : - SPC and shift-SPC replace ; and ,
|
||||||
|
":" 'eval-expression ; Elisp command
|
||||||
|
|
||||||
;; Moving rows rather than lines (in case of wrapping)
|
;; Moving rows rather than lines (in case of wrapping)
|
||||||
"j" 'evil-next-visual-line'
|
"j" 'evil-next-visual-line'
|
||||||
|
@ -128,8 +130,8 @@
|
||||||
(vmap "gc" 'evilnc-comment-or-uncomment-lines)
|
(vmap "gc" 'evilnc-comment-or-uncomment-lines)
|
||||||
|
|
||||||
;; Rotate-text (see elisp/rotate-text.el)
|
;; Rotate-text (see elisp/rotate-text.el)
|
||||||
(nmap (kbd "RET") 'rotate-word-at-point)
|
(nmap "!" 'rotate-word-at-point)
|
||||||
(vmap (kbd "RET") 'rotate-region)
|
(vmap "!" 'rotate-region)
|
||||||
;; (imap (kbd "RET") 'comment-indent-new-line)
|
;; (imap (kbd "RET") 'comment-indent-new-line)
|
||||||
;; Disable return for auto-completion, since tab does the trick
|
;; Disable return for auto-completion, since tab does the trick
|
||||||
(define-key ac-completing-map (kbd "RET") nil)
|
(define-key ac-completing-map (kbd "RET") nil)
|
||||||
|
|
11
init/core.el
11
init/core.el
|
@ -20,11 +20,15 @@
|
||||||
|
|
||||||
(defun kill-other-buffers ()
|
(defun kill-other-buffers ()
|
||||||
(interactive)
|
(interactive)
|
||||||
(mapc 'kill-buffer (cdr (buffer-list (current-buffer)))))
|
(mapc 'kill-buffer (cdr (buffer-list (current-buffer))))
|
||||||
|
(message "All other buffers killed")
|
||||||
|
)
|
||||||
|
|
||||||
(defun kill-all-buffers ()
|
(defun kill-all-buffers ()
|
||||||
(interactive)
|
(interactive)
|
||||||
(mapc 'kill-buffer (buffer-list)))
|
(mapc 'kill-buffer (buffer-list))
|
||||||
|
(message "All buffers killed")
|
||||||
|
)
|
||||||
|
|
||||||
;;;; Advice ;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;; Advice ;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
@ -52,7 +56,6 @@
|
||||||
ad-do-it))
|
ad-do-it))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;;;; My personal minor mode ;;;;;;;;
|
;;;; My personal minor mode ;;;;;;;;
|
||||||
|
|
||||||
(defvar my-mode-map (make-sparse-keymap))
|
(defvar my-mode-map (make-sparse-keymap))
|
||||||
|
@ -111,6 +114,8 @@
|
||||||
(defun major-mode-module-path ()
|
(defun major-mode-module-path ()
|
||||||
(expand-file-name (concat (major-mode-module-name) ".el") my-modules-dir))
|
(expand-file-name (concat (major-mode-module-name) ".el") my-modules-dir))
|
||||||
|
|
||||||
|
;; TODO: Write better eval-and-replace
|
||||||
|
|
||||||
|
|
||||||
;;;; Macros ;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;; Macros ;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
|
10
modules/env-ruby-mode.el
Normal file
10
modules/env-ruby-mode.el
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
|
||||||
|
; (require-package 'ruby-end)
|
||||||
|
|
||||||
|
(setq ruby-indent-level 4)
|
||||||
|
(setq ruby-deep-indent-paren nil)
|
||||||
|
|
||||||
|
(require 'ruby-mode-indent-fix)
|
||||||
|
|
||||||
|
;;
|
||||||
|
(provide 'env-ruby-mode)
|
|
@ -8,6 +8,8 @@
|
||||||
|
|
||||||
(ac-config-default)
|
(ac-config-default)
|
||||||
(ac-linum-workaround) ; Fix line number flux bug
|
(ac-linum-workaround) ; Fix line number flux bug
|
||||||
|
(diminish 'auto-complete-mode) ; Hide mode-line entry
|
||||||
|
(define-key ac-completing-map [return] nil)
|
||||||
|
|
||||||
(add-hook 'prog-mode-hook 'enable-path-completion)
|
(add-hook 'prog-mode-hook 'enable-path-completion)
|
||||||
(setq ac-auto-show-menu nil ; Suggestions box must be invoked manually (see core-keymaps.el)
|
(setq ac-auto-show-menu nil ; Suggestions box must be invoked manually (see core-keymaps.el)
|
||||||
|
|
|
@ -3,15 +3,18 @@
|
||||||
flyspell ; spell checker
|
flyspell ; spell checker
|
||||||
))
|
))
|
||||||
|
|
||||||
|
(diminish 'flyspell-mode " ?")
|
||||||
|
|
||||||
(setq ispell-program-name "aspell")
|
(setq ispell-program-name "aspell")
|
||||||
(setq ispell-list-command "--list")
|
(setq ispell-list-command "--list")
|
||||||
(setq flycheck-indication-mode 'right-fringe)
|
(setq flycheck-indication-mode 'right-fringe)
|
||||||
|
|
||||||
(setq-default flycheck-disabled-checkers '(emacs-lisp-checkdoc))
|
(setq-default flycheck-disabled-checkers '(emacs-lisp-checkdoc))
|
||||||
|
|
||||||
(add-hook 'prog-mode-hook #'global-flycheck-mode)
|
(add-hook 'after-init-hook (lambda() (global-flycheck-mode 1)))
|
||||||
(add-hook 'text-mode-hook (lambda () (flyspell-mode 1)))
|
(dolist (hook '(markdown-mode-hook git-commit-mode-hook org-mode-hook))
|
||||||
(add-hook 'conf-mode-hook (lambda () (flyspell-mode 1)))
|
(add-hook hook (lambda() (flyspell-mode 1))))
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
(provide 'mod-fly)
|
(provide 'mod-fly)
|
||||||
|
|
23
modules/mod-snippets.el
Normal file
23
modules/mod-snippets.el
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
|
||||||
|
;; Fix yasnippet keymaps so they only work in insert mode (why they
|
||||||
|
;; had to make this so complicated I don't know); must be defined
|
||||||
|
;; BEFORE we include yasnippet.
|
||||||
|
(defvar yas-minor-mode-map
|
||||||
|
(let ((map (make-sparse-keymap)))
|
||||||
|
(evil-define-key 'insert map [(tab)] 'yas-expand)
|
||||||
|
(evil-define-key 'insert map (kbd "TAB") 'yas-expand)
|
||||||
|
(evil-define-key 'insert map "\C-c&\C-s" 'yas-insert-snippet)
|
||||||
|
(evil-define-key 'insert map "\C-c&\C-n" 'yas-new-snippet)
|
||||||
|
(evil-define-key 'insert map "\C-c&\C-v" 'yas-visit-snippet-file)
|
||||||
|
map))
|
||||||
|
|
||||||
|
;; Require yasnippet *after* the minor mode map's been overwritten
|
||||||
|
(require-package 'yasnippet)
|
||||||
|
|
||||||
|
;;;#yasnippet
|
||||||
|
(yas-global-mode t)
|
||||||
|
(associate-mode 'snippet-mode '("emacs.+/snippets/") t)
|
||||||
|
(diminish 'yas-minor-mode)
|
||||||
|
|
||||||
|
;;
|
||||||
|
(provide 'mod-snippets)
|
Loading…
Add table
Add a link
Reference in a new issue