From fdbdd5f412a41b5ccd97512cea15095ec67a1dbd Mon Sep 17 00:00:00 2001 From: Ravi R Kiran Date: Fri, 29 Nov 2013 21:14:49 -0800 Subject: Add mark-handling commands diff --git a/init.el b/init.el index c64964f..28e7cf2 100644 --- a/init.el +++ b/init.el @@ -50,3 +50,9 @@ ;; Settings from M-x customize (load custom-file 'noerror) +(require 'bind-key) +(require 'use-package) +(require 'diminish) + +;; Initialize appearnace +(require 'ravi-init-marks) diff --git a/ravi-init-marks.el b/ravi-init-marks.el new file mode 100644 index 0000000..62f77aa --- /dev/null +++ b/ravi-init-marks.el @@ -0,0 +1,72 @@ +;;; ravi-init-marks.el --- Handling the mark + +;; Copyright (C) 2013 + +;; Author: +;; Keywords: + +;; 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 of the License, 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. If not, see . + +;;; Commentary: + +;; Handling the mark + +;;; Code: + +;; Show active region +(transient-mark-mode 1) +(make-variable-buffer-local 'transient-mark-mode) +(put 'transient-mark-mode 'permanent-local t) +(setq-default transient-mark-mode t) + +;; When popping the mark, continue popping until the cursor actually moves +;; Also, if the last command was a copy - skip past all the expand-region cruft. +;; Stolen from Magnar Sveen's emacs.d on github. +(defadvice pop-to-mark-command (around ensure-new-position activate) + (let ((p (point))) + (when (eq last-command 'save-region-or-current-line) + ad-do-it + ad-do-it + ad-do-it) + (dotimes (i 10) + (when (= p (point)) ad-do-it)))) + +;; Allow mark-based navigation even in transient-mark-mode; see +;; http://www.masteringemacs.org/articles/2010/12/22/fixing-mark-commands-transient-mark-mode/ + +(defun ravi/push-mark-no-activate () + "Pushes `point' to `mark-ring' and does not activate the region +Equivalent to \\[set-mark-command] when \\[transient-mark-mode] is disabled" + (interactive) + (push-mark (point) t nil) + (message "Pushed mark to ring")) +(bind-key "C-`" 'ravi/push-mark-no-activate) + +(defun ravi/jump-to-mark () + "Jumps to the local mark, respecting the `mark-ring' order. +This is the same as using \\[set-mark-command] with the prefix argument." + (interactive) + (set-mark-command 1)) +(bind-key "M-`" 'ravi/jump-to-mark) + +; Prevents C-x C-x from highlighting region +(defun ravi/exchange-point-and-mark-no-activate () + "Identical to \\[exchange-point-and-mark] but will not activate the region." + (interactive) + (exchange-point-and-mark) + (deactivate-mark nil)) +(define-key global-map [remap exchange-point-and-mark] 'ravi/exchange-point-and-mark-no-activate) + +(provide 'ravi-init-marks) +;;; ravi-init-marks.el ends here -- cgit v0.10.1