Mercurial > emacs
comparison lisp/emacs-lisp/lisp-mode.el @ 1865:05be3e0c082f
* lisp-mode.el (lisp-fill-paragraph): New function.
(shared-lisp-mode-map): Bind M-q to lisp-fill-paragraph.
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Sun, 14 Feb 1993 14:33:44 +0000 |
parents | c205d560cc22 |
children | 4f9d60f7de9d |
comparison
equal
deleted
inserted
replaced
1864:1354a2911d11 | 1865:05be3e0c082f |
---|---|
100 | 100 |
101 (if shared-lisp-mode-map | 101 (if shared-lisp-mode-map |
102 () | 102 () |
103 (setq shared-lisp-mode-map (make-sparse-keymap)) | 103 (setq shared-lisp-mode-map (make-sparse-keymap)) |
104 (define-key shared-lisp-mode-map "\e\C-q" 'indent-sexp) | 104 (define-key shared-lisp-mode-map "\e\C-q" 'indent-sexp) |
105 (define-key shared-lisp-mode-map "\M-q" 'lisp-fill-paragraph) | |
105 (define-key shared-lisp-mode-map "\177" 'backward-delete-char-untabify) | 106 (define-key shared-lisp-mode-map "\177" 'backward-delete-char-untabify) |
106 (define-key shared-lisp-mode-map "\t" 'lisp-indent-line)) | 107 (define-key shared-lisp-mode-map "\t" 'lisp-indent-line)) |
107 | 108 |
108 (defvar emacs-lisp-mode-map () | 109 (defvar emacs-lisp-mode-map () |
109 "Keymap for Emacs Lisp mode. | 110 "Keymap for Emacs Lisp mode. |
591 (lisp-indent-line)) | 592 (lisp-indent-line)) |
592 (let ((endmark (copy-marker end))) | 593 (let ((endmark (copy-marker end))) |
593 (indent-sexp endmark) | 594 (indent-sexp endmark) |
594 (set-marker endmark nil)))) | 595 (set-marker endmark nil)))) |
595 | 596 |
597 ;;;; Lisp paragraph filling commands. | |
598 | |
599 (defun lisp-fill-paragraph (&optional justify) | |
600 "Like \\[fill-paragraph], but handle Emacs Lisp comments. | |
601 If any of the current line is a comment, fill the comment or the | |
602 paragraph of it that point is in, preserving the comment's indentation | |
603 and initial semicolons." | |
604 (interactive "P") | |
605 (let ( | |
606 ;; Non-nil if the current line contains a comment. | |
607 has-comment | |
608 | |
609 ;; If has-comment, the appropriate fill-prefix for the comment. | |
610 comment-fill-prefix | |
611 ) | |
612 | |
613 ;; Figure out what kind of comment we are looking at. | |
614 (save-excursion | |
615 (beginning-of-line) | |
616 (cond | |
617 | |
618 ;; A line with nothing but a comment on it? | |
619 ((looking-at "[ \t]*;[; \t]*") | |
620 (setq has-comment t | |
621 comment-fill-prefix (buffer-substring (match-beginning 0) | |
622 (match-end 0)))) | |
623 | |
624 ;; A line with some code, followed by a comment? Remember that the | |
625 ;; semi which starts the comment shouldn't be part of a string or | |
626 ;; character. | |
627 ((progn | |
628 (while (not (looking-at ";\\|$")) | |
629 (skip-chars-forward "^;\n\"\\\\?") | |
630 (cond | |
631 ((eq (char-after (point)) ?\\) (forward-char 2)) | |
632 ((memq (char-after (point)) '(?\" ??)) (forward-sexp 1)))) | |
633 (looking-at ";+[\t ]*")) | |
634 (setq has-comment t) | |
635 (setq comment-fill-prefix | |
636 (concat (make-string (current-column) ? ) | |
637 (buffer-substring (match-beginning 0) (match-end 0))))))) | |
638 | |
639 (if (not has-comment) | |
640 (fill-paragraph justify) | |
641 | |
642 ;; Narrow to include only the comment, and then fill the region. | |
643 (save-restriction | |
644 (narrow-to-region | |
645 ;; Find the first line we should include in the region to fill. | |
646 (save-excursion | |
647 (while (and (zerop (forward-line -1)) | |
648 (looking-at "^[ \t]*;"))) | |
649 ;; We may have gone to far. Go forward again. | |
650 (or (looking-at "^[ \t]*;") | |
651 (forward-line 1)) | |
652 (point)) | |
653 ;; Find the beginning of the first line past the region to fill. | |
654 (save-excursion | |
655 (while (progn (forward-line 1) | |
656 (looking-at "^[ \t]*;"))) | |
657 (point))) | |
658 | |
659 ;; Lines with only semicolons on them can be paragraph boundaries. | |
660 (let ((paragraph-start (concat paragraph-start "\\|^[ \t;]*$")) | |
661 (paragraph-separate (concat paragraph-start "\\|^[ \t;]*$")) | |
662 (fill-prefix comment-fill-prefix)) | |
663 (fill-paragraph justify)))))) | |
664 | |
665 | |
596 (defun indent-code-rigidly (start end arg &optional nochange-regexp) | 666 (defun indent-code-rigidly (start end arg &optional nochange-regexp) |
597 "Indent all lines of code, starting in the region, sideways by ARG columns. | 667 "Indent all lines of code, starting in the region, sideways by ARG columns. |
598 Does not affect lines starting inside comments or strings, assuming that | 668 Does not affect lines starting inside comments or strings, assuming that |
599 the start of the region is not inside them. | 669 the start of the region is not inside them. |
600 | 670 |