(defun my/find-user-init-file () "Edit the `user-init-file', in another window." (interactive) (find-file-other-window user-init-file)) (global-set-key (kbd "C-c I") 'my/find-user-init-file) (defun my/new-empty-buffer () "Open a new empty buffer." (interactive) (let ((buf (generate-new-buffer "untitled"))) (switch-to-buffer buf) (funcall (and initial-major-mode)) (setq buffer-offer-save t))) (global-set-key (kbd "C-c n") 'my/new-empty-buffer) ;; http://whattheemacsd.com/key-bindings.el-01.html#disqus_thread (require 'linum) (defun my/goto-line-with-feedback () "Show line numbers temporarily, while prompting for the line number input" (interactive) (let ((line-numbers-off-p (not linum-mode))) (unwind-protect (progn (when line-numbers-off-p (linum-mode 1)) (call-interactively 'goto-line)) (when line-numbers-off-p (linum-mode -1))))) (global-set-key [remap goto-line] 'my/goto-line-with-feedback) ;; kill current buffer (global-set-key (kbd "C-x C-k") (lambda () (interactive) (kill-buffer (current-buffer)))) ;; delete up to non-whitespace character (global-set-key (kbd "C-c d") 'hungry-delete-forward) (defun ssh-dtach (host) "Open SSH connection to HOST and start dtach session." (interactive) (let ((explicit-shell-file-name "dtach") (explicit-dtach-args '("-A" "/tmp/emacs.dtach" "-z" "/bin/bash" "--noediting" "-login")) (default-directory (format "/ssh:%s:" host))) (shell (format "*ssh %s*" host)))) ;; http://blog.vivekhaldar.com/post/4809065853/dotemacs-extract-interactively-change-font-size (defun my/zoom-in () "Increase font size by 10 points" (interactive) (set-face-attribute 'default nil :height (+ (face-attribute 'default :height) 10))) (defun my/zoom-out () "Decrease font size by 10 points" (interactive) (set-face-attribute 'default nil :height (- (face-attribute 'default :height) 10))) ;; change font size, interactively (global-set-key (kbd "C->") 'my/zoom-in) (global-set-key (kbd "C-<") 'my/zoom-out) ;; easier way to jump to other window (global-set-key (kbd "M-o") 'other-window) (defun my/smart-open-line () "Insert an empty line after the current line. Position the cursor at its beginning, according to the current mode." (interactive) (move-end-of-line nil) (newline-and-indent)) (global-set-key [(shift return)] 'my/smart-open-line) (defun my/stop-using-minibuffer () "Abort any minibuffer action when it loses focus." (when (and (>= (recursion-depth) 1) (active-minibuffer-window)) (abort-recursive-edit))) (add-hook 'mouse-leave-buffer-hook 'my/stop-using-minibuffer) (defun my/fix-sentence (arg) "Add space to the end of a sentence." (interactive "p") (let ((sentence-end-double-space nil)) (loop for i from 1 to arg do (forward-sentence 1) (insert " ")))) ;; by Artur Malabarba and Drew, on emacs-devel (defun my/endless/comment-line (n) "Comment or uncomment current line and leave point after it. With positive prefix arg, apply to N lines including current one. With negative prefix arg, apply to -N lines above. When repeated, a negative prefix arg switches direction." (interactive "p") (when (eq last-command 'comment-line-backward) (setq n (- n))) (let ((range (list (line-beginning-position) (goto-char (line-end-position n))))) (comment-or-uncomment-region (apply #'min range) (apply #'max range))) (forward-line 1) (back-to-indentation) (unless (natnump n) (setq this-command 'comment-line-backward))) (global-set-key (kbd "C-;") 'my/endless/comment-line) ;; http://stackoverflow.com/a/18814469/519736 (defun my/copy-buffer-file-name (choice) "Copy the buffer-file-name to the kill-ring" (interactive "cCopy Buffer Name (F) Full, (D) Directory, (N) Name") (let ((new-kill-string) (name (if (eq major-mode 'dired-mode) (dired-get-filename) (or (buffer-file-name) "")))) (cond ((eq choice ?f) (setq new-kill-string name)) ((eq choice ?d) (setq new-kill-string (file-name-directory name))) ((eq choice ?n) (setq new-kill-string (file-name-nondirectory name))) (t (message "Quit"))) (when new-kill-string (message "%s copied" new-kill-string) (kill-new new-kill-string))))