1 | ;; ********************************************* |
---|
2 | ;; ***** Last change: MLO 2011-01-26 08:57 ***** |
---|
3 | ;; ********************************************* |
---|
4 | ; |
---|
5 | ; This file binds the following keys : |
---|
6 | ; ------------------------------------ |
---|
7 | ; C-c f: toggle auto-fill mode |
---|
8 | ; C-c g: move to line nr. N |
---|
9 | ; C-c r: redraw display |
---|
10 | |
---|
11 | (set-background-color "#F0FFFF") ; Azure |
---|
12 | (set-foreground-color "#000080") ; Navy blue |
---|
13 | (set-cursor-color "#FF0000") ; Red |
---|
14 | (set-mouse-color "#FF7256") ; Coral1 |
---|
15 | |
---|
16 | ;; Useful key bindings |
---|
17 | ;; =================== |
---|
18 | |
---|
19 | (global-set-key "\C-cf" 'auto-fill-mode) |
---|
20 | (global-set-key "\C-cg" 'goto-line) |
---|
21 | (global-set-key "\C-cr" 'redraw-display) |
---|
22 | |
---|
23 | ;; AUCTeX mode for (La)TeX |
---|
24 | ;; ======================= |
---|
25 | |
---|
26 | (setq load-path (cons "/opt/share/emacs/site-lisp" load-path)) |
---|
27 | (require 'tex-site) |
---|
28 | |
---|
29 | ;; Printer settings |
---|
30 | ;; ================ |
---|
31 | |
---|
32 | (setq ps-lpr-command "lpr" |
---|
33 | ps-lpr-switches '("-P" "Stylus-D92") |
---|
34 | lpr-command "lpr" |
---|
35 | lpr-switches '("-P" "Stylus-D92") |
---|
36 | ps-paper-type 'a4 |
---|
37 | ps-print-color-p t) |
---|
38 | |
---|
39 | ;; Mail settings |
---|
40 | ;; ============= |
---|
41 | |
---|
42 | (setq mail-host-address "pd.infn.it" |
---|
43 | message-user-organization "I.N.F.N. Padova - CDF/CMS cluster" |
---|
44 | user-mail-address (concat (user-login-name) "@pd.infn.it") |
---|
45 | mail-default-reply-to user-mail-address |
---|
46 | mail-signature t |
---|
47 | message-signature-file (expand-file-name "~/.signature")) |
---|
48 | |
---|
49 | ;; Newsreader settings |
---|
50 | ;; =================== |
---|
51 | |
---|
52 | (setq gnus-select-method '(nntp "powernews.libero.it") |
---|
53 | gnus-local-domain "pd.infn.it" |
---|
54 | gnus-local-organization "I.N.F.N. Padova - CDF/CMS cluster" |
---|
55 | gnus-signature-file (expand-file-name "~/.signature")) |
---|
56 | |
---|
57 | ;; Use 'aspell' as spell checker |
---|
58 | ;; ============================= |
---|
59 | |
---|
60 | (setq-default ispell-program-name "/opt/local/bin/aspell") |
---|
61 | |
---|
62 | ; This file binds the following keys : |
---|
63 | ; ------------------------------------ |
---|
64 | ; C-c b: move point to bottom-left of window |
---|
65 | ; C-c c: insert changestamp |
---|
66 | ; C-c d: scroll N lines down |
---|
67 | ; C-c e: shortcut for set-language-environment |
---|
68 | ; C-c n: kill the current line ('n' for 'nuke') |
---|
69 | ; C-c k: kill all from point to signature |
---|
70 | ; C-c p: toggle show matching parenthesis |
---|
71 | ; C-c s: toggle case-sensitive search |
---|
72 | ; C-c t: move point to top-left of the window |
---|
73 | ; C-c T: toggle tool-bar on and off |
---|
74 | ; C-c u: scroll N lines up |
---|
75 | ; C-c z: save the whole buffer in the kill ring |
---|
76 | ; [home]: move point to beginning of file |
---|
77 | ; [end]: move point to end of file |
---|
78 | ; [f13]: toggle insert/overwrite mode |
---|
79 | |
---|
80 | ;; Cosmetics |
---|
81 | ;; ========= |
---|
82 | |
---|
83 | (unless window-system ; When running in an xterm: |
---|
84 | (menu-bar-mode -1) ; - disable menu-bar; |
---|
85 | (set-terminal-coding-system 'iso-latin-1) ; - enable accented characters; |
---|
86 | (setq gnus-visual nil)) ; - disable gnus font-lock; |
---|
87 | |
---|
88 | (column-number-mode 1) ; Turn on column number show-up |
---|
89 | |
---|
90 | ; (setq frame-title-format "%b") ; Change title to the name of |
---|
91 | ; ; the buffer in current window |
---|
92 | (cond ((fboundp 'global-font-lock-mode) ; Turn on font-lock in all |
---|
93 | (global-font-lock-mode t) ; modes that support it |
---|
94 | (setq font-lock-maximum-decoration t) ; Customize colors |
---|
95 | ) |
---|
96 | ((fboundp 'turn-on-font-lock) |
---|
97 | (turn-on-font-lock) |
---|
98 | (setq font-lock-maximum-decoration t))) |
---|
99 | |
---|
100 | ; The following instruction is not recognized under Mac OS X |
---|
101 | |
---|
102 | ;(set-scroll-bar-mode 'right) ; Scroll-bar position: on the |
---|
103 | (cond ((commandp 'toggle-scroll-bar) ; right |
---|
104 | (toggle-scroll-bar 1))) |
---|
105 | |
---|
106 | (setq inhibit-startup-message t) ; Don't show the startup |
---|
107 | ; message |
---|
108 | |
---|
109 | (setq next-line-add-newlines nil) ; Don't add newlines when |
---|
110 | ; moving the cursor past EOF |
---|
111 | |
---|
112 | (fset 'yes-or-no-p 'y-or-n-p) ; Take y for yes, n for no |
---|
113 | |
---|
114 | (global-set-key "\C-ce" ; Use "C-c e" to toggle the language |
---|
115 | 'set-language-environment) ; (Latin-1 ->Latin-9 for the Euro) |
---|
116 | |
---|
117 | ;; Selects the mouse wheel scroll amount |
---|
118 | ;; ===================================== |
---|
119 | |
---|
120 | (setq mouse-wheel-scroll-amount |
---|
121 | (quote (3 ((shift) . 1) ((control) . nil)))) |
---|
122 | |
---|
123 | ;; Load the "show matching parentheses" package |
---|
124 | ;; ============================================ |
---|
125 | |
---|
126 | (require 'paren) ; Load |
---|
127 | (global-set-key "\C-cp" ; Use "C-c p" to toggle the |
---|
128 | 'toggle-highlight-paren-mode) ; highlight mode |
---|
129 | (show-paren-mode t) ; Set highlight mode on by default |
---|
130 | |
---|
131 | ;; AUCTeX specific |
---|
132 | ;; =============== |
---|
133 | |
---|
134 | (setq TeX-parse-self t ; Enable parse file on load |
---|
135 | TeX-auto-save nil ; Disable parse info saving |
---|
136 | TeX-auto-untabify t ; Change tabs to spaces |
---|
137 | font-latex-fontify-sectioning 'color) ; Title highligh. w/ color |
---|
138 | |
---|
139 | ;; Useful key bindings |
---|
140 | ;; =================== |
---|
141 | |
---|
142 | (global-set-key [home] 'beginning-of-buffer) |
---|
143 | (global-set-key [end] 'end-of-buffer) |
---|
144 | (global-set-key "\C-cs" 'toggle-case-fold-search) |
---|
145 | (global-set-key [f13] 'overwrite-mode) |
---|
146 | |
---|
147 | ;; Newsreader settings |
---|
148 | ;; =================== |
---|
149 | |
---|
150 | (setq gnus-subscribe-hierarchical-interactive t |
---|
151 | gnus-interactive-catchup nil |
---|
152 | gnus-large-newsgroup 300) |
---|
153 | |
---|
154 | (setq gnus-article-display-hook |
---|
155 | '(gnus-article-strip-leading-blank-lines |
---|
156 | gnus-article-remove-trailing-blank-lines |
---|
157 | gnus-article-strip-multiple-blank-lines |
---|
158 | gnus-article-hide-headers)) |
---|
159 | |
---|
160 | (setq gnus-visible-headers nil |
---|
161 | gnus-use-cache nil |
---|
162 | gnus-ignored-headers |
---|
163 | "^Path\\|^Message\\|^Return\\|^Refer\\|^NNTP\\|^X\\|^Mime\\|^Content") |
---|
164 | |
---|
165 | (setq gnus-post-method 'current) |
---|
166 | |
---|
167 | (setq gnus-summary-mode-line-format "Gnus: %G [%A] %Z" |
---|
168 | gnus-article-mode-line-format "Gnus: %G - %S%m" |
---|
169 | gnus-treat-display-smileys nil) |
---|
170 | |
---|
171 | ;; Sets, for the newsreader, the content of the 'Address', 'Reply-To' |
---|
172 | ;; and 'signature-file' variables in such a way that the resulting |
---|
173 | ;; post will point to a fake sender. For the mail agent, these fields |
---|
174 | ;; have the correct values. |
---|
175 | |
---|
176 | (setq gnus-posting-styles |
---|
177 | '((".*" |
---|
178 | (signature-file (expand-file-name "~/.signature")) |
---|
179 | (address "loreti@pd.infn.it") |
---|
180 | (Reply-to "loreti@pd.infn.it")) |
---|
181 | ((message-news-p) |
---|
182 | (signature-file (expand-file-name "~/.news-signature")) |
---|
183 | (address "mlo@foobar.it") |
---|
184 | (Reply-to "mlo@foobar.it")))) |
---|
185 | |
---|
186 | ;; Use "safari" as WWW browser |
---|
187 | |
---|
188 | (setq browse-url-browser-function 'browse-url-generic |
---|
189 | browse-url-generic-program "safari") |
---|
190 | |
---|
191 | ;; kill-to-signature |
---|
192 | ;; ----------------- |
---|
193 | ;; The following function will kill all the text from the point to the |
---|
194 | ;; first line that starts with "-- ". This is useful when replying to |
---|
195 | ;; a long email, but you don't want the rest of the quoted reply. The |
---|
196 | ;; function is globally is bounded to C-c k. |
---|
197 | |
---|
198 | (defun kill-to-signature () |
---|
199 | "Kill all text from point to the first line that starts with \"-- \". |
---|
200 | Usually that's the signature." |
---|
201 | (interactive) |
---|
202 | (delete-region (point) |
---|
203 | (save-excursion |
---|
204 | (search-forward-regexp "^-- ") |
---|
205 | (beginning-of-line) |
---|
206 | (point))) |
---|
207 | (insert "\n\n\n") |
---|
208 | (previous-line 2)) |
---|
209 | |
---|
210 | (global-set-key "\C-ck" 'kill-to-signature) |
---|
211 | |
---|
212 | ;; Indentation by blanks only |
---|
213 | ;; ========================== |
---|
214 | |
---|
215 | (setq-default indent-tabs-mode nil) |
---|
216 | |
---|
217 | ;; Enable some disabled commands |
---|
218 | ;; ============================= |
---|
219 | |
---|
220 | (put 'downcase-region 'disabled nil) |
---|
221 | (put 'upcase-region 'disabled nil) |
---|
222 | (put 'eval-expression 'disabled nil) |
---|
223 | |
---|
224 | ;; Turn on auto-fill mode for text-, TeX- and Mail- buffers |
---|
225 | ;; ======================================================== |
---|
226 | |
---|
227 | (add-hook 'text-mode-hook '(lambda () |
---|
228 | (progn (setq fill-column 70) (turn-on-auto-fill)))) |
---|
229 | |
---|
230 | (add-hook 'LaTeX-mode-hook '(lambda () |
---|
231 | (progn (setq fill-column 60) (turn-on-auto-fill)))) |
---|
232 | |
---|
233 | (add-hook 'mail-mode-hook '(lambda () |
---|
234 | (progn (setq fill-column 72) (turn-on-auto-fill)))) |
---|
235 | |
---|
236 | ;; Kill the current line (binded to C-c n) |
---|
237 | ;; ======================================= |
---|
238 | |
---|
239 | ; Define a variable which will store the previous column position |
---|
240 | |
---|
241 | (defvar previous-column nil "Save the column position") |
---|
242 | |
---|
243 | ; Define the nuke-line function: the current line is killed, the |
---|
244 | ; newline character is deleted, and the cursor is left on the same |
---|
245 | ; column on the next line. Because the kill-line function is used, |
---|
246 | ; the line can be later restored by using the yank commands. |
---|
247 | |
---|
248 | (defun nuke-line() |
---|
249 | "Kill an entire line, including the trailing newline character" |
---|
250 | (interactive) |
---|
251 | |
---|
252 | ; Store the current column position, and move the cursor to the end |
---|
253 | ; of the current line. |
---|
254 | |
---|
255 | (setq previous-column (current-column)) |
---|
256 | (end-of-line) |
---|
257 | |
---|
258 | ; If the length of the line is 0, there is no line. Only the |
---|
259 | ; newline character is deleted. |
---|
260 | |
---|
261 | (if (= (current-column) 0) |
---|
262 | (delete-char 1) |
---|
263 | |
---|
264 | ; This is the 'else' clause. Remove the line by moving to its |
---|
265 | ; start and then killing, then deleting the newline character, and |
---|
266 | ; finally restoring the column position. |
---|
267 | |
---|
268 | (progn |
---|
269 | (beginning-of-line) |
---|
270 | (kill-line) |
---|
271 | (delete-char 1) |
---|
272 | (move-to-column previous-column)))) |
---|
273 | |
---|
274 | (global-set-key "\C-cn" 'nuke-line) |
---|
275 | |
---|
276 | ;; changestamps |
---|
277 | ;; ============ |
---|
278 | |
---|
279 | ;; Insert "changestamp" at point (binded to C-c c) |
---|
280 | ;; ----------------------------------------------- |
---|
281 | |
---|
282 | (defvar changestamp-prefix "Last change: MLO " "'changestamp' prefix id") |
---|
283 | (defvar changestamp-suffix " *****" "'changestamp' suffix id") |
---|
284 | |
---|
285 | (defun insert-datetime () |
---|
286 | "Insert YYYY-MM-DD HH:MM at point" |
---|
287 | (insert (format-time-string "%Y-%m-%d %R" (current-time)))) |
---|
288 | |
---|
289 | (defun insert-changestamp () |
---|
290 | "Insert a 'changestamp' at point. |
---|
291 | A changestamp begins with 'Last change: MLO ' and whatever follows it, |
---|
292 | in a line ended by ' *****'" |
---|
293 | (interactive "*") |
---|
294 | (insert changestamp-prefix) |
---|
295 | (insert-datetime) |
---|
296 | (insert changestamp-suffix)) |
---|
297 | |
---|
298 | (global-set-key "\C-cc" 'insert-changestamp) |
---|
299 | |
---|
300 | ;; Automatically update the first existing changestamp |
---|
301 | ;; --------------------------------------------------- |
---|
302 | |
---|
303 | (defun update-changestamp () |
---|
304 | "Update the first existing 'changestamp'. |
---|
305 | A changestamp begins with 'Last change: MLO ' and whatever follows it, |
---|
306 | in a line ended by ' *****'" |
---|
307 | (interactive "*") |
---|
308 | (save-excursion |
---|
309 | (save-restriction |
---|
310 | (save-match-data |
---|
311 | (widen) |
---|
312 | (goto-char (point-min)) |
---|
313 | (if (search-forward changestamp-prefix nil t) |
---|
314 | (progn (kill-line) |
---|
315 | (insert-datetime) |
---|
316 | (insert changestamp-suffix)) |
---|
317 | nil))))) |
---|
318 | |
---|
319 | (add-hook 'write-file-hooks 'update-changestamp) |
---|
320 | |
---|
321 | ;; Automatically update all existing changestamps |
---|
322 | ;; ---------------------------------------------- |
---|
323 | |
---|
324 | (defun update-all-changestamps () |
---|
325 | "Update all existing 'changestamps'. |
---|
326 | A changestamp begins with 'Last change: MLO ' and whatever follows it, |
---|
327 | in a line ended by ' *****'" |
---|
328 | (interactive "*") |
---|
329 | (save-excursion |
---|
330 | (save-restriction |
---|
331 | (save-match-data |
---|
332 | (widen) |
---|
333 | (goto-char (point-min)) |
---|
334 | (while (search-forward changestamp-prefix nil t) |
---|
335 | (let ((start (point))) |
---|
336 | (if (re-search-forward |
---|
337 | (concat (regexp-quote changestamp-suffix) "$") |
---|
338 | (save-excursion (end-of-line) (point)) |
---|
339 | t) |
---|
340 | (progn (goto-char start) |
---|
341 | (kill-line) |
---|
342 | (insert-datetime) |
---|
343 | (insert changestamp-suffix)))))))) |
---|
344 | nil) |
---|
345 | |
---|
346 | ;; Cursor and point motion |
---|
347 | ;; ======================= |
---|
348 | ;; - scroll the window one/N lines at a time up and down |
---|
349 | ;; (binded to C-c u and C-c d, or C-u N C-c u/d); |
---|
350 | ;; - move point to start of top/bottom lines |
---|
351 | ;; (binded to C-c t and C-c b) |
---|
352 | |
---|
353 | (defun scroll-n-lines-up (&optional n) |
---|
354 | "Scroll the text up N lines (default: 1)" |
---|
355 | (interactive "P") |
---|
356 | (scroll-up (prefix-numeric-value n))) |
---|
357 | (global-set-key "\C-cu" 'scroll-n-lines-up) |
---|
358 | |
---|
359 | (defun scroll-n-lines-down (&optional n) |
---|
360 | "Scroll the text down N lines (default: 1)" |
---|
361 | (interactive "P") |
---|
362 | (scroll-down (prefix-numeric-value n))) |
---|
363 | (global-set-key "\C-cd" 'scroll-n-lines-down) |
---|
364 | |
---|
365 | (defun point-to-top () |
---|
366 | "Move point to top left in this window" |
---|
367 | (interactive) |
---|
368 | (move-to-window-line 0)) |
---|
369 | (global-set-key "\C-ct" 'point-to-top) |
---|
370 | |
---|
371 | (defun point-to-bottom () |
---|
372 | "Move point to bottom left in this window" |
---|
373 | (interactive) |
---|
374 | (move-to-window-line -1)) |
---|
375 | (global-set-key "\C-cb" 'point-to-bottom) |
---|
376 | |
---|
377 | ;; Symbolic links |
---|
378 | ;; ============== |
---|
379 | |
---|
380 | ;; Make them read-only |
---|
381 | ;; ------------------- |
---|
382 | |
---|
383 | (defun read-only-if-symlink () |
---|
384 | "When visiting a symlink, make the buffer read-only" |
---|
385 | (if (file-symlink-p buffer-file-name) |
---|
386 | (progn (setq buffer-read-only t) |
---|
387 | (message "This file is a symlink")))) |
---|
388 | (add-hook 'find-file-hooks 'read-only-if-symlink) |
---|
389 | |
---|
390 | ;; Define two functions to deal with them |
---|
391 | ;; -------------------------------------- |
---|
392 | |
---|
393 | (defun visit-symlink-target () |
---|
394 | "Replace this buffer with a buffer visiting the symlink target" |
---|
395 | (interactive) |
---|
396 | (if buffer-file-name |
---|
397 | (let ((target (file-symlink-p buffer-file-name))) |
---|
398 | (if target |
---|
399 | (find-alternate-file target) |
---|
400 | (error "Not visiting a symlink!"))) |
---|
401 | (error "Not visiting a file!"))) |
---|
402 | |
---|
403 | (defun clobber-symlink () |
---|
404 | "Replace the symlink with a copy of the target, and make it writable" |
---|
405 | (interactive) |
---|
406 | (if buffer-file-name |
---|
407 | (let ((target (file-symlink-p buffer-file-name))) |
---|
408 | (if target |
---|
409 | (if (yes-or-no-p (format "Replace %s with %s? " |
---|
410 | buffer-file-name target)) |
---|
411 | (progn (delete-file buffer-file-name) |
---|
412 | (write-file buffer-file-name) |
---|
413 | (setq buffer-read-only nil))) |
---|
414 | (error "Not visiting a symlink!"))) |
---|
415 | (error "Not visiting a file!"))) |
---|
416 | |
---|
417 | ;; C-like languages major mode settings |
---|
418 | ;; ==================================== |
---|
419 | |
---|
420 | (defconst my-c-style |
---|
421 | '((c-basic-offset . 2) |
---|
422 | (c-comment-only-line-offset . 0) |
---|
423 | (c-cleanup-list . (brace-else-brace |
---|
424 | brace-elseif-brace |
---|
425 | brace-catch-brace |
---|
426 | empty-defun-braces |
---|
427 | defun-close-semi |
---|
428 | list-close-comma |
---|
429 | scope-operator)) |
---|
430 | (c-hanging-braces-alist . ((brace-list-open) |
---|
431 | (substatement-open after) |
---|
432 | (block-close . c-snug-do-while) |
---|
433 | (extern-lang-open after) |
---|
434 | (class-open after) |
---|
435 | (defun-open after))) |
---|
436 | (c-offsets-alist . ((statement-block-intro . +) |
---|
437 | (knr-argdecl-intro . 0) |
---|
438 | (arglist-intro . +) |
---|
439 | (substatement-open . +) |
---|
440 | (label . 0) |
---|
441 | (statement-cont . +) |
---|
442 | (case-label . +) |
---|
443 | (arglist-close . 0)))) |
---|
444 | "MLO C programming style") |
---|
445 | |
---|
446 | (defun my-c-mode-common-hook () |
---|
447 | "Add my personal mode for C programming" |
---|
448 | (c-add-style "MLO" my-c-style t) |
---|
449 | ; (c-toggle-auto-state 1) |
---|
450 | (c-toggle-hungry-state 1) |
---|
451 | ; (setq c-echo-syntactic-information-p t) |
---|
452 | (setq indent-tabs-mode nil)) |
---|
453 | |
---|
454 | (add-hook 'c-mode-common-hook 'my-c-mode-common-hook) |
---|
455 | |
---|
456 | ;; Comment all lines in a region (half-box) |
---|
457 | ;; ======================================== |
---|
458 | |
---|
459 | ;; Customisation group, and related variables |
---|
460 | ;; ------------------------------------------ |
---|
461 | |
---|
462 | (defgroup half-box nil |
---|
463 | "Customisation of the 'half-box-comments'." |
---|
464 | :group 'editing |
---|
465 | :prefix "half-box-") |
---|
466 | (defcustom half-box-start ",-----" |
---|
467 | "Starting line for 'half-box-comments'." |
---|
468 | :type 'string :group 'half-box) |
---|
469 | (defcustom half-box-mid "| " |
---|
470 | "Left border of the 'half-box-comments'." |
---|
471 | :type 'string :group 'half-box) |
---|
472 | (defcustom half-box-end "`-----" |
---|
473 | "Ending line for 'half-box-comments'." |
---|
474 | :type 'string :group 'half-box) |
---|
475 | |
---|
476 | ;; Create an half-box comment block |
---|
477 | ;; -------------------------------- |
---|
478 | |
---|
479 | (defun half-box-comment (start end) |
---|
480 | "Comment all lines in the region (adding two more lines); 'half-box' style." |
---|
481 | (interactive "*r") |
---|
482 | (save-excursion |
---|
483 | (save-restriction |
---|
484 | (narrow-to-region |
---|
485 | (progn (goto-char start) (beginning-of-line) (point)) |
---|
486 | (progn (goto-char end) (end-of-line) (point))) |
---|
487 | (goto-char (point-min)) |
---|
488 | (beginning-of-line) |
---|
489 | (insert half-box-start "\n") |
---|
490 | (while (not (eobp)) |
---|
491 | (insert half-box-mid) |
---|
492 | (forward-line 1)) |
---|
493 | (insert half-box-end "\n")))) |
---|
494 | |
---|
495 | ;; Create an half-box comment block, C/C++ specific |
---|
496 | ;; ------------------------------------------------ |
---|
497 | |
---|
498 | (defun half-cbox-comment (start end) |
---|
499 | "Comment all lines in the region (adding two more lines); |
---|
500 | C/C++ program 'half-box' style." |
---|
501 | (interactive "*r") |
---|
502 | (let ((half-box-start "/**") (half-box-mid " | ") (half-box-end "**/")) |
---|
503 | (half-box-comment start end))) |
---|
504 | |
---|
505 | ;; Create a full-box comment block, C/C++ specific |
---|
506 | ;; ----------------------------------------------- |
---|
507 | |
---|
508 | (defun full-box-comment (start end) |
---|
509 | "Comment all lines in the region (adding two more lines); 'full-box' style." |
---|
510 | (interactive "*r") |
---|
511 | (save-excursion |
---|
512 | (save-restriction |
---|
513 | (narrow-to-region |
---|
514 | (progn (goto-char start) (beginning-of-line) (point)) |
---|
515 | (progn (goto-char end) (end-of-line) (point))) |
---|
516 | (delete-trailing-whitespace) |
---|
517 | (goto-char (point-min)) ; Compute in "maxlen" the length of |
---|
518 | (beginning-of-line) ; the longest line, plus 1. |
---|
519 | (let ((maxlen 0) (pos (point)) (linelen 0)) |
---|
520 | (while (= 0 (forward-line)) |
---|
521 | (setq maxlen (max maxlen (- (point) pos)) |
---|
522 | pos (point))) ; End <while loop on lines> |
---|
523 | (goto-char (point-min)) ; Insert upper border |
---|
524 | (beginning-of-line) |
---|
525 | (insert "/*") |
---|
526 | (setq linelen maxlen) |
---|
527 | (while (>= linelen 0) (insert "-") (setq linelen (1- linelen))) |
---|
528 | (insert "*\n") |
---|
529 | (setq linelen 0 pos (1- (point))) |
---|
530 | (while (not (eobp)) ; Insert left and right border |
---|
531 | (insert " | ") ; for every line |
---|
532 | (end-of-line) |
---|
533 | (setq linelen (- (- (point) pos) 3)) |
---|
534 | (while (< linelen maxlen) (insert " ") (setq linelen (1+ linelen))) |
---|
535 | (insert " |") |
---|
536 | (setq pos (point)) |
---|
537 | (forward-line 1)) ; End <while loop on lines> |
---|
538 | (insert " *") ; Insert lower border |
---|
539 | (while (>= maxlen 0) (insert "-") (setq maxlen (1- maxlen))) |
---|
540 | (insert "*/\n")))) ; End <save-excursion> |
---|
541 | (forward-line 1)) ; Restore point |
---|
542 | |
---|
543 | ;; Save the whole buffer into the kill ring and the X clipboard: |
---|
544 | ;; - this function is also binded to 'C-c z'; |
---|
545 | ;; - this function is also binded to the first entry in the |
---|
546 | ;; "Edit" menu, that will have title "Store buffer". |
---|
547 | ;; ------------------------------------------------------------- |
---|
548 | |
---|
549 | (defun save-whole-buffer () |
---|
550 | "Select the whole buffer, and copy the selection to the kill ring" |
---|
551 | (interactive) |
---|
552 | (save-excursion |
---|
553 | (save-restriction |
---|
554 | (widen) |
---|
555 | (clipboard-kill-ring-save (point-min) (point-max)) |
---|
556 | (message "The whole buffer has been stored in the kill ring")))) |
---|
557 | |
---|
558 | (global-set-key "\C-cz" 'save-whole-buffer) |
---|
559 | |
---|
560 | ;; End of /home/loreti/local_emacs.el |
---|
561 | ;; ================================== |
---|
562 | |
---|
563 | ;; End of .emacs |
---|
564 | ;; ============= |
---|