aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJim Blandy1993-02-14 14:33:44 +0000
committerJim Blandy1993-02-14 14:33:44 +0000
commit6338c7ba53598d34b4c17fa22811488b51c66da1 (patch)
tree73dbb57222337f1c99150eea7258597d61712cca
parent29130b950e699f967beab4d378db796d8b7fa2e5 (diff)
downloademacs-6338c7ba53598d34b4c17fa22811488b51c66da1.tar.gz
emacs-6338c7ba53598d34b4c17fa22811488b51c66da1.zip
* lisp-mode.el (lisp-fill-paragraph): New function.
(shared-lisp-mode-map): Bind M-q to lisp-fill-paragraph.
-rw-r--r--lisp/emacs-lisp/lisp-mode.el70
1 files changed, 70 insertions, 0 deletions
diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el
index b0f823e0103..ca464984613 100644
--- a/lisp/emacs-lisp/lisp-mode.el
+++ b/lisp/emacs-lisp/lisp-mode.el
@@ -102,6 +102,7 @@
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
@@ -593,6 +594,75 @@ ENDPOS is encountered."
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.
601If any of the current line is a comment, fill the comment or the
602paragraph of it that point is in, preserving the comment's indentation
603and 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.
598Does not affect lines starting inside comments or strings, assuming that 668Does not affect lines starting inside comments or strings, assuming that