boon/boon-extras.el

75 lines
2.4 KiB
EmacsLisp
Raw Normal View History

;;; boon-extras.el --- An Ergonomic Command Mode -*- lexical-binding: t -*-
2014-10-19 14:17:46 +02:00
;;; Commentary:
2014-10-26 13:35:23 +01:00
;; This module provides (arguably) more useful bindings to the "x"
;; prefix map.
2014-10-19 14:17:46 +02:00
;;; Code:
(require 'boon-core)
2014-10-23 13:31:30 +02:00
(require 'boon-main)
2014-10-19 14:17:46 +02:00
(defun boon-adjust-indent ()
"Adjust indentation of the region or current line."
2014-10-19 14:17:46 +02:00
(interactive)
(unless (use-region-p)
(set-mark (line-beginning-position))
(end-of-line))
(call-interactively 'indent-rigidly))
2014-10-19 14:17:46 +02:00
(defun boon-query-replace ()
"Query replace; but if the region is active, replace its contents"
(interactive)
(if (and (use-region-p) (eq (- (line-number-at-pos (region-end)) (line-number-at-pos (region-beginning))) 0))
2015-10-24 21:33:38 +02:00
(let ((selection (buffer-substring-no-properties (region-beginning) (region-end))))
(perform-replace
2014-10-19 14:17:46 +02:00
selection
(read-string "Replace region with:")
t ; query
nil ; not a regexp
nil ; not delimited
nil ; no specific repeat count
nil ; default keymap
(point-min-marker)
(point-max-marker) ; replace in the whole buffer
))
(call-interactively 'query-replace)))
(defun boon-toggle-comment (regs)
2014-10-26 20:46:51 +01:00
"Toggle comments in the regions REGS."
(interactive (list (boon-spec-region "toggle comment")))
(dolist (reg regs)
(comment-or-uncomment-region (min (car reg) (cdr reg))
2014-10-26 20:46:51 +01:00
(max (car reg) (cdr reg)))))
2014-10-26 20:36:04 +01:00
2014-10-19 22:50:50 +02:00
(define-key boon-x-map "rr" 'boon-query-replace) ; replace the region if it is selected
(define-key boon-x-map "t" 'boon-toggle-comment) ; commenT
(define-key boon-x-map "i" 'boon-adjust-indent)
(define-key boon-x-map [(return)] 'boon-split-line)
(define-key boon-x-map " " 'boon-split-word)
2015-11-11 22:28:20 +01:00
(define-key boon-x-map "U" 'undo-tree-visualize)
2014-10-19 22:50:50 +02:00
(define-key boon-x-map "O" 'previous-window) ;; o is next window
(define-key boon-x-map "S" 'save-some-buffers)
(define-key boon-x-map "\\" 'align-regexp)
(define-key boon-x-map "b" 'ido-switch-buffer)
(define-key boon-x-map "f" 'ido-find-file)
2014-10-19 23:01:11 +02:00
(define-key boon-x-map "h" help-map)
2014-10-19 22:50:50 +02:00
(define-key boon-x-map "j" 'join-line)
(define-key boon-x-map "k" 'kill-this-buffer)
(define-key boon-x-map "l" 'fill-paragraph)
(define-key boon-x-map "M" 'menu-bar-open)
(define-key boon-x-map "s" 'save-buffer)
(define-key boon-x-map "vv" 'magit-status)
(define-key boon-x-map "g" 'magit-status)
(define-key boon-x-map "x" 'helm-M-x)
2015-12-13 22:28:11 +01:00
(eval-after-load 'flycheck
'(define-key boon-x-map "y" flycheck-command-map)
)
2014-10-19 14:17:46 +02:00
(provide 'boon-extras)
;;; boon-extras.el ends here