Skip to content

Instantly share code, notes, and snippets.

@gennad
Last active October 8, 2015 22:17
Show Gist options
  • Select an option

  • Save gennad/3396504 to your computer and use it in GitHub Desktop.

Select an option

Save gennad/3396504 to your computer and use it in GitHub Desktop.
latest .emacs
(setq org-directory "~/Dropbox/org/")
(setq next-line-add-newlines nil)
(load-file "~/.emacs.d/emacs-for-python/epy-init.el")
(setq flymake-gui-warnings-enabled nil)
(blink-cursor-mode (- (*) (*) (*)))
(add-to-list 'load-path "~/.emacs.d/nav/")
(require 'nav)
(add-hook 'before-save-hook 'delete-trailing-whitespace)
(defun my-other-delete-trailing-blank-lines ()
"Deletes all blank lines at the end of the file, even the last one"
(interactive)
(save-excursion
(save-restriction
(widen)
(goto-char (point-max))
(delete-blank-lines)
(let ((trailnewlines (abs (skip-chars-backward "\n\t"))))
(if (> trailnewlines 0)
(progn
(delete-char trailnewlines)))))))
;Add magit
(add-to-list 'load-path "~/.emacs.d/magit")
(require 'magit)
(require 'org-install)
(add-to-list 'auto-mode-alist '("\\.org$" . org-mode))
(define-key global-map "\C-cl" 'org-store-link)
(define-key global-map "\C-ca" 'org-agenda)
(setq org-log-done t)
;; etags
(defun create-tags (dir-name)
"Create tags file."
(interactive "DDirectory: ")
(eshell-command
(format "find %s -type f -name \"*.py\" | etags -" dir-name)))
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(desktop-enable t nil (desktop))
'(desktop-save-mode t nil (desktop))
'(org-agenda-files (quote ("~/org/1.org")))
'(save-place t nil (saveplace))
'(ediff-split-window-function (quote split-window-horizontally))
)
(desktop-save-mode 1)
(add-to-list 'load-path "~/.emacs.d/")
;;(require 'iy-go-to-char)
(require 'go-to-char)
(global-set-key (kbd "C-c f") 'go-to-char-forward)
(global-set-key (kbd "C-c F") 'go-to-char-backward)
(epy-setup-checker "/usr/local/bin/pyflakes %f")
(tool-bar-mode -1)
;; Set to the location of your Org files on your local system
;(setq org-directory "~/org")
;; Set to the name of the file where new notes will be stored
(require 'org)
(setq org-mobile-inbox-for-pull "~/org/flagged.org")
;; Set to <your Dropbox root directory>/MobileOrg.
(setq org-mobile-directory "~/Dropbox/MobileOrg")
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
(setq rsense-home "~/.emacs.d/rsense")
(add-to-list 'load-path (concat rsense-home "/etc"))
;(require 'rsense)
(require 'tramp)
(setq tramp-default-method "scp")
(require 'whitespace)
(setq whitespace-style '(face empty tabs lines-tail trailing))
(global-whitespace-mode t)
(column-number-mode 1)
(eval-after-load "vc-hooks"
'(define-key vc-prefix-map "=" 'ediff-revision))
(defun ediff-current-buffer-revision ()
"Run Ediff to diff current buffer's file against VC depot.
Uses `vc.el' or `rcs.el' depending on `ediff-version-control-package'."
(interactive)
(let ((file (or (buffer-file-name)
(error "Current buffer is not visiting a file"))))
(if (and (buffer-modified-p)
(y-or-n-p (message "Buffer %s is modified. Save buffer? "
(buffer-name))))
(save-buffer (current-buffer)))
(ediff-load-version-control)
(funcall
(intern (format "ediff-%S-internal" ediff-version-control-package))
"" "" nil)))
(global-set-key [f6] 'compile)
(setq compilation-ask-about-save nil)
(set-face-attribute 'default nil :height 145 :weight 'normal)
(set-default-font "Inconsolata-17")
(defun toggle-window-split ()
(interactive)
(if (= (count-windows) 2)
(let* ((this-win-buffer (window-buffer))
(next-win-buffer (window-buffer (next-window)))
(this-win-edges (window-edges (selected-window)))
(next-win-edges (window-edges (next-window)))
(this-win-2nd (not (and (<= (car this-win-edges)
(car next-win-edges))
(<= (cadr this-win-edges)
(cadr next-win-edges)))))
(splitter
(if (= (car this-win-edges)
(car (window-edges (next-window))))
'split-window-horizontally
'split-window-vertically)))
(delete-other-windows)
(let ((first-win (selected-window)))
(funcall splitter)
(if this-win-2nd (other-window 1))
(set-window-buffer (selected-window) this-win-buffer)
(set-window-buffer (next-window) next-win-buffer)
(select-window first-win)
(if this-win-2nd (other-window 1))))))
(define-key ctl-x-4-map "t" 'toggle-window-split)
(add-to-list 'load-path "~/.emacs.d/pydoc-info/")
(require 'pydoc-info)
(epy-setup-ipython)
;;(global-hl-line-mode t) ;; To enable
;;(set-face-background 'hl-line "black") ;; change with the color that you like
;; for a list of colors: http://raebear.net/comp/emacscolors.html
(require 'highlight-indentation)
(add-hook 'python-mode-hook 'highlight-indentation)
;; Auto refresh buffers
(global-auto-revert-mode t)
(setq-default indent-tabs-mode nil)
(defun my-isearch-word-at-point ()
(interactive)
(call-interactively 'isearch-forward-regexp))
(defun my-isearch-yank-word-hook ()
(when (equal this-command 'my-isearch-word-at-point)
(let ((string (concat "\\<"
(buffer-substring-no-properties
(progn (skip-syntax-backward "w_") (point))
(progn (skip-syntax-forward "w_") (point)))
"\\>")))
(if (and isearch-case-fold-search
(eq 'not-yanks search-upper-case))
(setq string (downcase string)))
(setq isearch-string string
isearch-message
(concat isearch-message
(mapconcat 'isearch-text-char-description
string ""))
isearch-yank-flag t)
(isearch-search-and-update))))
(add-hook 'isearch-mode-hook 'my-isearch-yank-word-hook)
(when (fboundp 'winner-mode)
(winner-mode 1))
(require 'magit)
(autoload 'mo-git-blame-file "mo-git-blame" nil t)
(autoload 'mo-git-blame-current "mo-git-blame" nil t)
(require 'python-pep8)
; Cmd as meta key. Also, need to set caps lock as C system-wide.
(setq mac-option-key-is-meta nil)
(setq mac-command-key-is-meta t)
(setq mac-command-modifier 'meta)
(setq mac-option-modifier nil)
; Shell - Mx eshell
; M-y to yank in isearch
; Dot mode C-.
(require 'dot-mode)
(add-hook 'find-file-hooks 'dot-mode-on)
; C-M-f go to bracket closing or string end.
;; (defun my-horizontal-recenter ()
;; "make the point horizontally centered in the window"
;; (interactive)
;; (let ((mid (/ (window-width) 2))
;; (line-len (save-excursion (end-of-line) (current-column)))
;; (cur (current-column)))
;; (if (< mid cur)
;; (set-window-hscroll (selected-window)
;; (- cur mid)))))
;; (global-set-key (kbd "C-M-l") 'my-horizontal-recenter)
; Registers: C-x r s <reg> - save and C-x r i <reg> to insert
(require 'list-register)
(global-set-key (kbd "C-x r v") 'list-register)
;; C-x r <SPC> R -- C-x r j R -- save buffer/position in register R, and jump back to it
;; C-x r w R -- C-x r j R -- save window configuration in register R, and jump back to it
; M-r reposition cursor
; C-M-a -- go to beginning of the fuction
; C-m-e -- go to end of the function
; Back C-x o
(defun back-window ()
(interactive)
(other-window -1))
(global-set-key (kbd "C-x O") 'back-window)
(setq calendar-week-start-day 1)
(global-set-key (kbd "C-c <tab>") 'imenu)
(setq python-imenu-make-tree nil)
(setq python-imenu-include-defun-type nil)
(require 'etags) ;; provides `find-tag-default' in Emacs 21.
(defun isearch-yank-regexp (regexp)
"Pull REGEXP into search regexp."
(let ((isearch-regexp nil)) ;; Dynamic binding of global.
(isearch-yank-string regexp))
(isearch-search-and-update))
(defun isearch-yank-symbol (&optional partialp)
"Put symbol at current point into search string.
If PARTIALP is non-nil, find all partial matches."
(interactive "P")
(let* ((sym (find-tag-default))
;; Use call of `re-search-forward' by `find-tag-default' to
;; retrieve the end point of the symbol.
(sym-end (match-end 0))
(sym-start (- sym-end (length sym))))
(if (null sym)
(message "No symbol at point")
(goto-char sym-start)
;; For consistent behavior, restart Isearch from starting point
;; (or end point if using `isearch-backward') of symbol.
(isearch-search)
(if partialp
(isearch-yank-string sym)
(isearch-yank-regexp
(concat "\\_<" (regexp-quote sym) "\\_>"))))))
(defun isearch-current-symbol (&optional partialp)
"Incremental search forward with symbol under point.
Prefixed with \\[universal-argument] will find all partial
matches."
(interactive "P")
(let ((start (point)))
(isearch-forward-regexp nil 1)
(isearch-yank-symbol partialp)))
(defun isearch-backward-current-symbol (&optional partialp)
"Incremental search backward with symbol under point.
Prefixed with \\[universal-argument] will find all partial
matches."
(interactive "P")
(let ((start (point)))
(isearch-backward-regexpnil 1)
(isearch-yank-symbol partialp)))
(require 'goto-last-change)
(global-set-key "\C-x\C-\\" 'goto-last-change)
; Repeat last command C-x z. z to repeat again.
(require 'xml-rpc)
(require 'weblogger)
; tags-search - search name in project
; Search a file in project
(add-to-list 'load-path "~/.emacs.d/eproject")
(require 'eproject)
(require 'eproject-extras)
; C-c t -- google translate
(require 'google-translate)
(global-set-key "\C-ct" 'google-translate-query-translate)
(setq google-translate-default-target-language "ru")
(setq google-translate-default-source-language "en")
; Nosemacs
(require 'nose)
; 3 buffers on screen
(defun disabled-key ()
"Disables keys"
(interactive)
(print "Key is disabled !")
)
;; All arrow keys are disabled
(global-set-key (kbd "<up>") 'disabled-key)
(global-set-key (kbd "<down>") 'disabled-key)
(global-set-key (kbd "<left>") 'disabled-key)
(global-set-key (kbd "<right>") 'disabled-key)
; Copy word under the cursor
(defun get-point (symbol &optional arg)
"get the point"
(funcall symbol arg)
(point)
)
(defun copy-thing (begin-of-thing end-of-thing &optional arg)
"copy thing between beg & end into kill ring"
(save-excursion
(let ((beg (get-point begin-of-thing 1))
(end (get-point end-of-thing arg)))
(copy-region-as-kill beg end)))
)
(defun copy-word (&optional arg)
"Copy words at point into kill-ring"
(interactive "P")
(copy-thing 'backward-sexp 'forward-sexp arg)
;;(paste-to-mark arg)
)
(global-set-key (kbd "C-c w") 'copy-word)
; C-h for backspace, C-w for backspace word, C-? for help
(global-set-key (kbd "C-?") 'help-command)
(global-set-key (kbd "M-?") 'mark-paragraph)
(global-set-key (kbd "C-h") 'delete-backward-char)
(global-set-key (kbd "C-w") 'backward-kill-word)
(global-set-key (kbd "C-;") 'universal-argument)
(global-set-key (kbd "M-h") 'kill-region)
(global-set-key [backspace] 'disabled-key)
(global-set-key [M-backspace] 'disabled-key)
(global-set-key [return] 'disabled-key)
(require 'buffer-move)
;; Diff buffer with saved file:
;;diff-buffer-with-file
;;ediff-current-file
; C-n, C-p for autocomplete
(yas/global-mode 1)
(require 'auto-complete-config)
(ac-config-default)
(setq ac-use-menu-map t)
(define-key ac-menu-map "\C-n" 'ac-next)
(define-key ac-menu-map "\C-p" 'ac-previous)
(define-key ac-menu-map "\C-o" 'ac-complete)
;;(add-to-list 'load-path "~/.emacs.d/plugins/yasnippet")
;;(require 'yasnippet)
;;(global-set-ke (kbd "C-i") 'yas/expand)
;;(setq yas/also-auto-indent-first-line t)
;;(add-to-list 'load-path "~/.emacs.d/plugins/autocomplete/")
;;(add-to-list 'ac-dictionary-directories "~/.emacs.d/plugins/autocomplete/ac-dict")
(defun undo-line ()
"Like C-u in bash"
(interactive)
(move-beginning-of-line 1)
(kill-line)
)
(global-set-key (kbd "C-u") 'undo-line)
(add-to-list 'load-path "/usr/local/Cellar/emacs/24.2/Emacs.app/Contents/share/emacs/site-lisp/w3m")
(require 'w3m-load)
(setq w3m-use-cookies t)
; M-w to copy line, C-w to delete (without C-a)
(require 'whole-line-or-region)
(whole-line-or-region-mode)
(setq auto-save-interval 100)
; Auto save directory
(setq backup-directory-alist
`((".*" . ,temporary-file-directory)))
(setq auto-save-file-name-transforms
`((".*" ,temporary-file-directory t)))
; Smex
(require 'smex) ; Not needed if you use package.el
(smex-initialize) ; Can be omitted. This might cause a (minimal) delay
; when Smex is auto-initialized on its first run.
(global-set-key (kbd "M-x") 'smex)
(global-set-key (kbd "M-X") 'smex-major-mode-commands)
;; This is your old M-x.
(global-set-key (kbd "C-c C-c M-x") 'execute-extended-command)
; Switch between 2 buffers
(defun switch-to-previous-buffer ()
(interactive)
(switch-to-buffer (other-buffer (current-buffer) 1)))
(global-set-key (kbd "M-[") 'switch-to-previous-buffer)
(global-set-key (kbd "M-]") 'other-window)
;; (add-to-list 'load-path "~/.emacs.d/org-caldav")
;; (require org-caldav)
;; (setq org-caldav-url "https://www.google.com/calendar/dav")
;; (setq org-caldav-calendar-id "")
;; - Set `org-caldav-files' to the list of org files you would like to
;; sync. For everything else, you can use the org-icalendar-*
;; variables, since org-caldav uses that package to generate the
;; events.
;;
;; - Set `org-caldav-inbox' to an org filename where new entries from
;; the calendar should be stored.
;;
;; Call `org-caldav-sync' to start the sync. The URL package will ask
;; you for username/password for accessing the calendar.
(defun select-current-word ()
"Select the word under cursor.
“word” here is considered any alphanumeric sequence with “_” or “-”."
(interactive)
(let (pt)
(skip-chars-backward "-_A-Za-z0-9")
(setq pt (point))
(skip-chars-forward "-_A-Za-z0-9")
(set-mark pt)
))
(global-set-key (kbd "C-M-h") 'select-current-word)
;(require 'auto-highlight-symbol)
;(global-auto-highlight-symbol-mode t)
;; (global-set-key (kbd "C-\\") 'ahs-forward)
;; (global-set-key (kbd "C-'") 'ahs-backward)
(require 'highlight-symbol)
(global-set-key (kbd "C-M-/") 'highlight-symbol-next)
(global-set-key (kbd "C-M-,") 'highlight-symbol-prev)
(global-set-key [(control f3)] 'highlight-symbol-at-point)
(global-set-key [(control meta f3)] 'highlight-symbol-query-replace)
(define-key isearch-mode-map "\C-h" 'delete-backward-char)
;; (add-hook 'isearch-mode-hook
;; (lambda ()
;; (define-key isearch-mode-map (kbd "C-h") 'isearch-delete-char
;; )))
(defun next-word (p)
"Move point to the beginning of the next word, past any spaces"
(interactive "d")
(forward-word)
(forward-word)
(backward-word))
(global-set-key "\M-f" 'next-word)
(defun prev-word (p)
"Move point to the beginning of the next word, past any spaces"
(interactive "d")
(backward-word)
(backward-word)
(forward-word))
(global-set-key "\M-b" 'prev-word)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment