-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindirect-region.el
64 lines (49 loc) · 1.62 KB
/
indirect-region.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
;;; indirect-region.el --- act like indirect-buffer but for region
;; Copyright © 2012 Sébastien Gross <seb•ɑƬ•chezwam•ɖɵʈ•org>
;; Author: Sébastien Gross <seb•ɑƬ•chezwam•ɖɵʈ•org>
;; Version: 0.0.1.20120124
;; Keywords: emacs
;; Created: 2012-01-24
;; Last changed: 2012-01-24 19:40:20
;; Licence: WTFPL, grab your copy here: http://sam.zoy.org/wtfpl/
;; This file is NOT part of GNU Emacs.
;;; Commentary:
;;
;; Based on Mario Lang's indirect-region
;; http://www.emacswiki.org/emacs/IndirectBuffers#toc3
;;
;; To install:
;; (require 'indirect-region)
;; (define-key 'Control-X-prefix "r" 'indirect-region)
;;
;;; Code:
(defgroup indirect-region nil
"`indirect-region' customization."
:group 'convenience)
(defcustom indirect-region-hook nil
"List of hook functions run by `indirect-region' after visiting source file."
:type 'hook
:group 'indirect-region)
;;;###autoload
(defun indirect-region (start end &optional arg)
"Edit the current region in another buffer.
If called with `universal-argument', ask for a specific mode."
(interactive "r\nP")
(let ((buffer-name (generate-new-buffer-name
(format"*indirect %s*" (buffer-name))))
(mode (if arg
(intern
(completing-read
"Mode: "
(mapcar (lambda (e)
(list (symbol-name e)))
(apropos-internal "-mode$" 'commandp))
nil t))
major-mode)))
(pop-to-buffer (make-indirect-buffer (current-buffer) buffer-name))
(narrow-to-region start end)
(funcall mode)
(run-hooks 'indirect-region-hook)
(goto-char (point-min))))
(provide 'indirect-region)
;;; indirect-region.el ends here