-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path06.el
53 lines (39 loc) · 1.45 KB
/
06.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
;; Write a function that will display the first 60 characters of the
;; current buffer, even if you have narrowed the buffer to its latter half
;; so that the first line is inaccessible. Restore point, mark, and
;; narrowing. For this exercise, you need to use a whole potpourri of
;; functions, including ‘save-restriction’, ‘widen’, ‘goto-char’,
;; ‘point-min’, ‘message’, and ‘buffer-substring’.
;; (‘buffer-substring’ is a previously unmentioned function you will
;; have to investigate yourself; or perhaps you will have to use
;; ‘buffer-substring-no-properties’ or ‘filter-buffer-substring’ …, yet
;; other functions. Text properties are a feature otherwise not discussed
;; here. *Note Text Properties: (elisp)Text Properties.)
;; Additionally, do you really need ‘goto-char’ or ‘point-min’? Or can
;; you write the function without them?
;; with goto-char and point-min
(defun copy-first-60 ()
"Print first 60 chars of a 'current-buffer'"
(interactive)
(save-excursion
(save-restriction
(widen)
(goto-char 60)
(message (buffer-substring-no-properties (point-min) (point)))
))
)
;; Usage
(copy-first-60)
;; without goto-char and point-min
(defun copy-first-60-min ()
"Print first 60 chars of a 'current-buffer'"
(interactive)
(save-excursion
(save-restriction
(widen)
(message (buffer-substring-no-properties 1 60))
)
)
)
;; Usage
(copy-first-60-min)