-
Notifications
You must be signed in to change notification settings - Fork 1
/
bartuer-mark.el
executable file
·70 lines (64 loc) · 2.29 KB
/
bartuer-mark.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
65
66
67
68
69
(easy-mmode-defmap bartuer-note-mode-map
`(("\C-c\C-c" . bartuer-note-done)
("\C-cc" . bartuer-note-done))
"Keymap for the `bartuer-note-mode' (to edit version control log messages).")
(define-derived-mode bartuer-note-mode text-mode "Note"
"Major mode for editing note .
\\{bartuer-note-mode-map}
Turning on Note mode runs the normal hook `bartuer-note-mode-hook'."
(make-local-variable 'bartuer-note-mode-variant)
(make-local-variable 'note-buffer)
(make-local-variable 'mark-buffer)
(setq bartuer-note-mode-variant t))
(defun bartuer-check-mark-mode-line ()
(goto-char (point-min))
(let ((first-endline (search-forward "\n" nil t)))
(goto-char (point-min))
(unless (search-forward "mode:grep"
first-endline
t)
(goto-char (point-min))
(insert-string "-*- mode:grep -*-\n"))))
(defun bartuer-note-done ()
(interactive)
(set-buffer (car mark-buffer))
(toggle-read-only -1)
(goto-char (point-max))
(insert-string "\n")
(set-buffer (car note-buffer))
(let ((start (point-min))
(end (point-max)))
(append-to-buffer (car mark-buffer) start end)
(set-buffer (car mark-buffer))
(basic-save-buffer)
(set-buffer (car note-buffer))
(message "note added")
(kill-buffer-and-window)
(set-buffer note-orginal-buffer)
(deactivate-mark)))
(defun bartuer-read-mark ()
(interactive)
(setq mark-buffer
(list (find-file-noselect
(format "%s-marks" (bookmark-buffer-name)))))
(setq note-orginal-buffer (current-buffer))
(let ((target-file-name (buffer-file-name))
(target-line-number (line-number-at-pos))
(target-buffer (current-buffer))
(start (region-beginning))
(end (region-end)))
(save-excursion
(set-buffer (car mark-buffer))
(bartuer-check-mark-mode-line)
(grep-mode)
(toggle-read-only -1)
(goto-char (point-max))
(insert-string (format "\n\n%s:%d: \n["
target-file-name
target-line-number))
(insert-buffer-substring target-buffer start end)
(insert-string "]"))
(setq note-buffer
(list (switch-to-buffer-other-window "bartuer-note")))
(set-buffer (car note-buffer))
(bartuer-note-mode)))