/[emacs]/emacs/lisp/emacs-lisp/lisp-mode.el
ViewVC logotype

Diff of /emacs/lisp/emacs-lisp/lisp-mode.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.134 by walters, Sun Jan 13 05:40:59 2002 UTC revision 1.134.4.1 by miles, Fri Apr 4 06:20:16 2003 UTC
# Line 107  Line 107 
107           (purecopy (concat "^\\s-*("           (purecopy (concat "^\\s-*("
108                             (eval-when-compile                             (eval-when-compile
109                               (regexp-opt                               (regexp-opt
110                                '("defgroup" "deftype" "defstruct" "defclass"                                '("defgroup" "deftheme" "deftype" "defstruct"
111                                  "define-condition" "define-widget" "defface"                                  "defclass" "define-condition" "define-widget"
112                                  "defpackage") t))                                  "defface" "defpackage") t))
113                             "\\s-+'?\\(\\sw\\(\\sw\\|\\s_\\)+\\)"))                             "\\s-+'?\\(\\sw\\(\\sw\\|\\s_\\)+\\)"))
114           2))           2))
115    
# Line 121  Line 121 
121  (put 'defun*    'doc-string-elt 3)  (put 'defun*    'doc-string-elt 3)
122  (put 'defvar   'doc-string-elt 3)  (put 'defvar   'doc-string-elt 3)
123  (put 'defcustom 'doc-string-elt 3)  (put 'defcustom 'doc-string-elt 3)
124    (put 'deftheme 'doc-string-elt 2)
125  (put 'defconst 'doc-string-elt 3)  (put 'defconst 'doc-string-elt 3)
126  (put 'defmacro 'doc-string-elt 3)  (put 'defmacro 'doc-string-elt 3)
127  (put 'defmacro* 'doc-string-elt 3)  (put 'defmacro* 'doc-string-elt 3)
# Line 132  Line 133 
133  (put 'define-generic-mode 'doc-string-elt 7)  (put 'define-generic-mode 'doc-string-elt 7)
134  ;; define-global-mode has no explicit docstring.  ;; define-global-mode has no explicit docstring.
135  (put 'easy-mmode-define-global-mode 'doc-string-elt 0)  (put 'easy-mmode-define-global-mode 'doc-string-elt 0)
136  (put 'define-ibuffer-filter 'doc-string-elt 3)  (put 'define-ibuffer-filter 'doc-string-elt 2)
137  (put 'define-ibuffer-op 'doc-string-elt 3)  (put 'define-ibuffer-op 'doc-string-elt 3)
138  (put 'define-ibuffer-sorter 'doc-string-elt 3)  (put 'define-ibuffer-sorter 'doc-string-elt 2)
139    
140  (defun lisp-font-lock-syntactic-face-function (state)  (defun lisp-font-lock-syntactic-face-function (state)
141    (if (nth 3 state)    (if (nth 3 state)
# Line 402  which see." Line 403  which see."
403  (defun last-sexp-setup-props (beg end value alt1 alt2)  (defun last-sexp-setup-props (beg end value alt1 alt2)
404    "Set up text properties for the output of `eval-last-sexp-1'.    "Set up text properties for the output of `eval-last-sexp-1'.
405  BEG and END are the start and end of the output in current-buffer.  BEG and END are the start and end of the output in current-buffer.
406  VALUE is the Lisp value printed, ALT1 and ALT2 are strings for the  VALUE is the Lisp value printed, ALT1 and ALT2 are strings for the
407  alternative printed representations that can be displayed."  alternative printed representations that can be displayed."
408    (let ((map (make-sparse-keymap)))    (let ((map (make-sparse-keymap)))
409      (define-key map "\C-m" 'last-sexp-toggle-display)      (define-key map "\C-m" 'last-sexp-toggle-display)
410      (define-key map [down-mouse-2] 'mouse-set-point)      (define-key map [down-mouse-2] 'mouse-set-point)
411      (define-key map [mouse-2] 'last-sexp-toggle-display)      (define-key map [mouse-2] 'last-sexp-toggle-display)
412      (add-text-properties      (add-text-properties
413       beg end       beg end
414       `(printed-value (,value ,alt1 ,alt2)       `(printed-value (,value ,alt1 ,alt2)
415                       mouse-face highlight                       mouse-face highlight
416                       keymap ,map                       keymap ,map
417                       help-echo "RET, mouse-2: toggle abbreviated display"                       help-echo "RET, mouse-2: toggle abbreviated display"
418                       rear-nonsticky (mouse-face keymap help-echo                       rear-nonsticky (mouse-face keymap help-echo
# Line 429  alternative printed representations that Line 430  alternative printed representations that
430              (point (point)))              (point (point)))
431          (delete-region beg end)          (delete-region beg end)
432          (insert (nth 1 value))          (insert (nth 1 value))
433          (last-sexp-setup-props beg (point)          (last-sexp-setup-props beg (point)
434                                 (nth 0 value)                                 (nth 0 value)
435                                 (nth 2 value)                                 (nth 2 value)
436                                 (nth 1 value))                                 (nth 1 value))
# Line 507  With argument, print output into current Line 508  With argument, print output into current
508                           (not (null print-level)))                           (not (null print-level)))
509                       (not (string= unabbreviated                       (not (string= unabbreviated
510                                     (buffer-substring-no-properties beg end))))                                     (buffer-substring-no-properties beg end))))
511              (last-sexp-setup-props beg end value              (last-sexp-setup-props beg end value
512                                     unabbreviated                                     unabbreviated
513                                     (buffer-substring-no-properties beg end))                                     (buffer-substring-no-properties beg end))
514              ))))))              ))))))
# Line 821  This function also returns nil meaning d Line 822  This function also returns nil meaning d
822      (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)      (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)
823      (if (and (elt state 2)      (if (and (elt state 2)
824               (not (looking-at "\\sw\\|\\s_")))               (not (looking-at "\\sw\\|\\s_")))
825          ;; car of form doesn't seem to be a a symbol          ;; car of form doesn't seem to be a symbol
826          (progn          (progn
827            (if (not (> (save-excursion (forward-line 1) (point))            (if (not (> (save-excursion (forward-line 1) (point))
828                        calculate-lisp-indent-last-sexp))                        calculate-lisp-indent-last-sexp))
# Line 1054  ENDPOS is encountered." Line 1055  ENDPOS is encountered."
1055    
1056  ;;;; Lisp paragraph filling commands.  ;;;; Lisp paragraph filling commands.
1057    
1058    (defcustom emacs-lisp-docstring-fill-column 65
1059      "Value of `fill-column' to use when filling a docstring.
1060    Any non-integer value means do not use a different value of
1061    `fill-column' when filling docstrings."
1062      :type '(choice (integer)
1063                     (const :tag "Use the current `fill-column'" t))
1064      :group 'lisp)
1065    
1066  (defun lisp-fill-paragraph (&optional justify)  (defun lisp-fill-paragraph (&optional justify)
1067    "Like \\[fill-paragraph], but handle Emacs Lisp comments.    "Like \\[fill-paragraph], but handle Emacs Lisp comments and docstrings.
1068  If any of the current line is a comment, fill the comment or the  If any of the current line is a comment, fill the comment or the
1069  paragraph of it that point is in, preserving the comment's indentation  paragraph of it that point is in, preserving the comment's indentation
1070  and initial semicolons."  and initial semicolons."
1071    (interactive "P")    (interactive "P")
1072    (let (    (or (fill-comment-paragraph justify)
1073          ;; Non-nil if the current line contains a comment.        ;; Point is on a program line (a line no comment); we are interested
1074          has-comment        ;; particularly in docstring lines.
1075          ;;
1076          ;; Non-nil if the current line contains code and a comment.        ;; We bind `paragraph-start' and `paragraph-separate' temporarily.  They
1077          has-code-and-comment        ;; are buffer-local, but we avoid changing them so that they can be set
1078          ;; to make `forward-paragraph' and friends do something the user wants.
1079          ;; If has-comment, the appropriate fill-prefix for the comment.        ;;
1080          comment-fill-prefix        ;; `paragraph-start': The `(' in the character alternative and the
1081          )        ;; left-singlequote plus `(' sequence after the \\| alternative prevent
1082          ;; sexps and backquoted sexps that follow a docstring from being filled
1083      ;; Figure out what kind of comment we are looking at.        ;; with the docstring.  This setting has the consequence of inhibiting
1084      (save-excursion        ;; filling many program lines that are not docstrings, which is sensible,
1085        (beginning-of-line)        ;; because the user probably asked to fill program lines by accident, or
1086        (cond        ;; expecting indentation (perhaps we should try to do indenting in that
1087          ;; case).  The `;' and `:' stop the paragraph being filled at following
1088         ;; A line with nothing but a comment on it?        ;; comment lines and at keywords (e.g., in `defcustom').  Left parens are
1089         ((looking-at "[ \t]*;[; \t]*")        ;; escaped to keep font-locking, filling, & paren matching in the source
1090          (setq has-comment t        ;; file happy.
1091                comment-fill-prefix (buffer-substring (match-beginning 0)        ;;
1092                                                      (match-end 0))))        ;; `paragraph-separate': A clever regexp distinguishes the first line of
1093          ;; a docstring and identifies it as a paragraph separator, so that it
1094         ;; A line with some code, followed by a comment?  Remember that the        ;; won't be filled.  (Since the first line of documentation stands alone
1095         ;; semi which starts the comment shouldn't be part of a string or        ;; in some contexts, filling should not alter the contents the author has
1096         ;; character.        ;; chosen.)  Only the first line of a docstring begins with whitespace
1097         ((let ((state (syntax-ppss (line-end-position))))        ;; and a quotation mark and ends with a period or (rarely) a comma.
1098            (when (nth 4 state)        ;;
1099              (goto-char (nth 8 state))        ;; The `fill-column' is temporarily bound to
1100              (looking-at ";+[\t ]*")))        ;; `emacs-lisp-docstring-fill-column' if that value is an integer.
1101          (setq has-comment t has-code-and-comment t)        (let ((paragraph-start (concat paragraph-start
1102          (setq comment-fill-prefix                                       "\\|\\s-*\\([\(;:\"]\\|`\(\\)"))
1103                (concat (make-string (/ (current-column) tab-width) ?\t)              (paragraph-separate
1104                        (make-string (% (current-column) tab-width) ?\ )               (concat paragraph-separate "\\|\\s-*\".*[,\\.]$"))
1105                        (buffer-substring (match-beginning 0) (match-end 0)))))))              (fill-column (if (integerp emacs-lisp-docstring-fill-column)
1106                                 emacs-lisp-docstring-fill-column
1107      (if (not has-comment)                             fill-column)))
1108          ;; `paragraph-start' is set here (not in the buffer-local          (fill-paragraph justify))
1109          ;; variable so that `forward-paragraph' et al work as        ;; Never return nil.
1110          ;; expected) so that filling (doc) strings works sensibly.        t))
         ;; Adding the opening paren to avoid the following sexp being  
         ;; filled means that sexps generally aren't filled as normal  
         ;; text, which is probably sensible.  The `;' and `:' stop the  
         ;; filled para at following comment lines and keywords  
         ;; (typically in `defcustom').  
         (let ((paragraph-start (concat paragraph-start  
                                        "\\|\\s-*[\(;:\"]"))  
               ;; Avoid filling the first line of docstring.  
               (paragraph-separate  
                (concat paragraph-separate "\\|\\s-*\".*\\.$")))  
           (fill-paragraph justify))  
   
       ;; Narrow to include only the comment, and then fill the region.  
       (save-excursion  
         (save-restriction  
           (beginning-of-line)  
           (narrow-to-region  
            ;; Find the first line we should include in the region to fill.  
            (save-excursion  
              (while (and (zerop (forward-line -1))  
                          (looking-at "[ \t]*;")))  
              ;; We may have gone too far.  Go forward again.  
              (or (looking-at ".*;")  
                  (forward-line 1))  
              (point))  
            ;; Find the beginning of the first line past the region to fill.  
            (save-excursion  
              (while (progn (forward-line 1)  
                            (looking-at "[ \t]*;")))  
              (point)))  
   
           ;; Lines with only semicolons on them can be paragraph boundaries.  
           (let* ((paragraph-start (concat paragraph-start "\\|[ \t;]*$"))  
                  (paragraph-separate (concat paragraph-start "\\|[ \t;]*$"))  
                  (paragraph-ignore-fill-prefix nil)  
                  (fill-prefix comment-fill-prefix)  
                  (after-line (if has-code-and-comment  
                                  (save-excursion  
                                    (forward-line 1) (point))))  
                  (end (progn  
                         (forward-paragraph)  
                         (or (bolp) (newline 1))  
                         (point)))  
                  ;; If this comment starts on a line with code,  
                  ;; include that like in the filling.  
                  (beg (progn (backward-paragraph)  
                              (if (eq (point) after-line)  
                                  (forward-line -1))  
                              (point))))  
             (fill-region-as-paragraph beg end  
                                       justify nil  
                                       (save-excursion  
                                         (goto-char beg)  
                                         (if (looking-at fill-prefix)  
                                             nil  
                                           (re-search-forward comment-start-skip)  
                                           (point))))))))  
     t))  
1111    
1112  (defun indent-code-rigidly (start end arg &optional nochange-regexp)  (defun indent-code-rigidly (start end arg &optional nochange-regexp)
1113    "Indent all lines of code, starting in the region, sideways by ARG columns.    "Indent all lines of code, starting in the region, sideways by ARG columns.

Legend:
Removed from v.1.134  
changed lines
  Added in v.1.134.4.1

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26