-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathregion-to-frame.el
40 lines (39 loc) · 1.93 KB
/
region-to-frame.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
(defun region-to-frame ()
(interactive)
(unless (region-active-p)
(error "No region active."))
(let* ((start (region-beginning))
(end (region-end))
(start-line (save-excursion (line-number-at-pos start)))
(start-column (save-excursion (goto-char start) (current-column)))
(start-string (if (< 0 start-column)
(format "+%s:%s" start-line start-column)
(format "+%s"start-line)))
(end-line (save-excursion (line-number-at-pos end)))
(end-column (save-excursion (goto-char end) (current-column)))
(end-string (if (< 0 end-column)
(format "+%s:%s" end-line end-column)
(format "+%s" end-line)))
(new-buffer (make-indirect-buffer (current-buffer)
(generate-new-buffer-name (format "*Fragment %s%s%s*"
(buffer-name (current-buffer))
start-string
end-string))
t)))
(with-current-buffer new-buffer
(narrow-to-region start end)
(let ((frame-height 1)
(frame-width 0))
(save-excursion
(goto-char (point-max))
(while (< (point-min) (point))
(forward-line -1)
(incf frame-height)
(setf frame-width (max frame-width (- (line-end-position) (line-beginning-position))))))
(let ((frame (new-frame (list (cons 'width frame-width)
(cons 'height (+ 2 frame-height))
(cons 'minibuffer t)))))
(select-frame frame)
(when (region-active-p)
(deactivate-mark)))))))
(provide 'region-to-frame)