aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichaël Cadilhac2007-08-17 22:51:24 +0000
committerMichaël Cadilhac2007-08-17 22:51:24 +0000
commit8a4c50518400514864e55a6a84e956744b072a3a (patch)
tree6e990a77051f9058141c3d82d28f52bcd81c4422
parent18e08bf7a2b62a19ab0cb018c133907dfab78560 (diff)
downloademacs-8a4c50518400514864e55a6a84e956744b072a3a.tar.gz
emacs-8a4c50518400514864e55a6a84e956744b072a3a.zip
(meta-indent-calculate-last): Remove.
(meta-indent-current-nesting): Use a computation of the nesting instead. (meta-indent-current-indentation): Indentation is given according to nesting and if the previous line was finished or not. (meta-indent-unfinished-line): Tell if the current line ends with a finished expression. (meta-indent-looking-at-code): Like `looking-at', but checks if the point is a string before. (meta-indent-level-count): Use it. Don't count parenthesis as it's done in the nesting function. (meta-indent-in-string-p): Tell if the current point is in a string. (meta-indent-calculate): Treat b-o-b as a special case. Use the previous functions.
-rw-r--r--lisp/ChangeLog18
-rw-r--r--lisp/progmodes/meta-mode.el153
2 files changed, 128 insertions, 43 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 577d1f65a25..400909ecd29 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,21 @@
12007-08-09 Micha,Ak(Bl Cadilhac <michael@cadilhac.name>
2
3 * progmodes/meta-mode.el (meta-indent-calculate-last): Remove.
4 (meta-indent-current-nesting): Use a computation of the nesting
5 instead.
6 (meta-indent-current-indentation): Indentation is given according
7 to nesting and if the previous line was finished or not.
8 (meta-indent-unfinished-line): Tell if the current line ends with
9 a finished expression.
10 (meta-indent-looking-at-code): Like `looking-at', but checks if
11 the point is a string before.
12 (meta-indent-level-count): Use it. Don't count parenthesis as it's
13 done in the nesting function.
14 (meta-indent-in-string-p): Tell if the current point is in a
15 string.
16 (meta-indent-calculate): Treat b-o-b as a special case. Use the
17 previous functions.
18
12007-08-17 Thien-Thi Nguyen <ttn@gnuvola.org> 192007-08-17 Thien-Thi Nguyen <ttn@gnuvola.org>
2 20
3 * emacs-lisp/copyright.el (copyright-limit): New defsubst. 21 * emacs-lisp/copyright.el (copyright-limit): New defsubst.
diff --git a/lisp/progmodes/meta-mode.el b/lisp/progmodes/meta-mode.el
index a2fd9cdab04..6b911dd1e7a 100644
--- a/lisp/progmodes/meta-mode.el
+++ b/lisp/progmodes/meta-mode.el
@@ -51,7 +51,7 @@
51;; these lines to your startup file: 51;; these lines to your startup file:
52;; 52;;
53;; (add-hook 'meta-mode-load-hook 53;; (add-hook 'meta-mode-load-hook
54;; '(lambda () (require 'meta-buf))) 54;; (lambda () (require 'meta-buf)))
55;; 55;;
56;; The add-on package loaded this way may in turn make use of the 56;; The add-on package loaded this way may in turn make use of the
57;; mode-hooks provided in this package to activate additional features 57;; mode-hooks provided in this package to activate additional features
@@ -605,14 +605,16 @@ If the list was changed, sort the list and remove duplicates first."
605 605
606(defun meta-indent-calculate () 606(defun meta-indent-calculate ()
607 "Return the indentation of current line of Metafont or MetaPost source." 607 "Return the indentation of current line of Metafont or MetaPost source."
608 ;; Indentation within strings is not considered as Meta* don't allow multi
609 ;; line strings.
608 (save-excursion 610 (save-excursion
609 (back-to-indentation) 611 (back-to-indentation)
610 (cond 612 (cond
611 ;; Comments to the left margin. 613 ;; Comments to the left margin.
612 ((and meta-left-comment-regexp 614 ((and meta-left-comment-regexp
613 (looking-at meta-left-comment-regexp)) 615 (looking-at meta-left-comment-regexp))
614 0) 616 0)
615 ;; Comments to the right margin. 617 ;; Comments to the right margin.
616 ((and meta-right-comment-regexp 618 ((and meta-right-comment-regexp
617 (looking-at meta-right-comment-regexp)) 619 (looking-at meta-right-comment-regexp))
618 comment-column) 620 comment-column)
@@ -620,42 +622,113 @@ If the list was changed, sort the list and remove duplicates first."
620 ((and meta-ignore-comment-regexp 622 ((and meta-ignore-comment-regexp
621 (looking-at meta-ignore-comment-regexp)) 623 (looking-at meta-ignore-comment-regexp))
622 (current-indentation)) 624 (current-indentation))
625 ;; Beginning of buffer.
626 ((eq (point-at-bol) (point-min))
627 0)
623 ;; Backindent at end of environments. 628 ;; Backindent at end of environments.
624 ((looking-at 629 ((meta-indent-looking-at-code
625 (concat "\\<" meta-end-environment-regexp "\\>")) 630 (concat "\\<" meta-end-environment-regexp "\\>"))
626 (- (meta-indent-calculate-last) meta-indent-level)) 631 (- (meta-indent-current-indentation) meta-indent-level))
627 ;; Backindent at keywords within environments. 632 ;; Backindent at keywords within environments.
628 ((looking-at 633 ((meta-indent-looking-at-code
629 (concat "\\<" meta-within-environment-regexp "\\>")) 634 (concat "\\<" meta-within-environment-regexp "\\>"))
630 (- (meta-indent-calculate-last) meta-indent-level)) 635 (- (meta-indent-current-indentation) meta-indent-level))
631 (t (meta-indent-calculate-last))))) 636 (t (meta-indent-current-indentation)))))
632 637
633(defun meta-indent-calculate-last () 638(defun meta-indent-in-string-p ()
634 "Return the indentation of previous line of Metafont or MetaPost source." 639 "Tell if the point is in a string."
635 (save-restriction 640 (or (nth 3 (syntax-ppss))
636 (widen) 641 (eq (get-text-property (point) 'face) font-lock-string-face)))
642
643(defun meta-indent-looking-at-code (regexp)
644 "Same as `looking-at' but checks that the point is not in a string."
645 (unless (meta-indent-in-string-p)
646 (looking-at regexp)))
647
648(defun meta-indent-previous-line ()
649 "Go to the previous line of code, skipping comments."
650 (skip-chars-backward "\n\t ")
651 (move-to-column (current-indentation))
652 ;; Ignore comments.
653 (while (and (looking-at comment-start) (not (bobp)))
637 (skip-chars-backward "\n\t ") 654 (skip-chars-backward "\n\t ")
638 (move-to-column (current-indentation)) 655 (if (not (bobp))
639 ;; Ignore comments. 656 (move-to-column (current-indentation)))))
640 (while (and (looking-at comment-start) (not (bobp))) 657
641 (skip-chars-backward "\n\t ") 658(defun meta-indent-unfinished-line ()
642 (if (not (bobp)) 659 "Tell if the current line of code ends with an unfinished expression."
643 (move-to-column (current-indentation)))) 660 (save-excursion
644 (cond 661 (end-of-line)
645 ((bobp) 0) 662 ;; Skip backward the comments.
646 (t (+ (current-indentation) 663 (while (search-backward comment-start (point-at-bol) t))
647 (meta-indent-level-count) 664 ;; Search for the end of the previous expression.
648 (cond 665 (if (search-backward ";" (point-at-bol) t)
649 ;; Compensate for backindent at end of environments. 666 (progn (while (and (meta-indent-in-string-p)
650 ((looking-at 667 (search-backward ";" (point-at-bol) t)))
651 (concat "\\<"meta-end-environment-regexp "\\>")) 668 (if (= (char-after) ?\;)
652 meta-indent-level) 669 (forward-char)
653 ;; Compensate for backindent within environments. 670 (beginning-of-line)))
654 ((looking-at 671 (beginning-of-line))
655 (concat "\\<" meta-within-environment-regexp "\\>")) 672 ;; See if the last statement of the line is environment-related,
656 meta-indent-level) 673 ;; or exists at all.
657 (t 0))))) 674 (if (meta-indent-looking-at-code
658 )) 675 (concat "[ \t]*\\($\\|" (regexp-quote comment-start)
676 "\\|\\<" meta-end-environment-regexp "\\>"
677 "\\|\\<" meta-begin-environment-regexp "\\>"
678 "\\|\\<" meta-within-environment-regexp "\\>\\)"))
679 nil
680 t)))
681
682(defun meta-indent-current-indentation ()
683 "Return the indentation wanted for the current line of code."
684 (+ (meta-indent-current-nesting)
685 (if (save-excursion
686 (back-to-indentation)
687 (and (not (looking-at (concat "\\<" meta-end-environment-regexp "\\>"
688 "\\|\\<" meta-within-environment-regexp "\\>")))
689 (progn (meta-indent-previous-line)
690 (meta-indent-unfinished-line))))
691 meta-indent-level
692 0)))
693
694(defun meta-indent-current-nesting ()
695 "Return the indentation according to the nearest environment keyword."
696 (save-excursion
697 (save-restriction
698 (widen)
699 (back-to-indentation)
700 (let ((to-add 0))
701 ;; If we found some environment marker backward...
702 (if (catch 'found
703 (while (re-search-backward
704 (concat "(\\|)\\|\\<" meta-end-environment-regexp "\\>"
705 "\\|\\<" meta-begin-environment-regexp "\\>"
706 "\\|\\<" meta-within-environment-regexp "\\>")
707 nil t)
708 ;; If we aren't in a string or in a comment, we've found something.
709 (unless (or (meta-indent-in-string-p)
710 (nth 4 (syntax-ppss)))
711 (cond ((= (char-after) ?\()
712 (setq to-add (+ to-add meta-indent-level)))
713 ((= (char-after) ?\))
714 (setq to-add (- to-add meta-indent-level)))
715 (t (throw 'found t))))))
716 (progn
717 ;; ... then use it to compute the current indentation.
718 (back-to-indentation)
719 (+ to-add (current-indentation) (meta-indent-level-count)
720 ;; Compensate for backindent of end and within keywords.
721 (if (meta-indent-looking-at-code
722 (concat "\\<" meta-end-environment-regexp "\\>\\|"
723 "\\<" meta-within-environment-regexp "\\>"))
724 meta-indent-level
725 ;; Compensate for unfinished line.
726 (if (save-excursion
727 (meta-indent-previous-line)
728 (meta-indent-unfinished-line))
729 (- meta-indent-level)
730 0))))
731 0)))))
659 732
660(defun meta-indent-level-count () 733(defun meta-indent-level-count ()
661 "Count indentation change for begin-end commands in the current line." 734 "Count indentation change for begin-end commands in the current line."
@@ -671,18 +744,12 @@ If the list was changed, sort the list and remove duplicates first."
671 (goto-char (match-beginning 0)) 744 (goto-char (match-beginning 0))
672 (cond 745 (cond
673 ;; Count number of begin-end keywords within line. 746 ;; Count number of begin-end keywords within line.
674 ((looking-at 747 ((meta-indent-looking-at-code
675 (concat "\\<" meta-begin-environment-regexp "\\>")) 748 (concat "\\<" meta-begin-environment-regexp "\\>"))
676 (setq count (+ count meta-indent-level))) 749 (setq count (+ count meta-indent-level)))
677 ((looking-at 750 ((meta-indent-looking-at-code
678 (concat "\\<" meta-end-environment-regexp "\\>")) 751 (concat "\\<" meta-end-environment-regexp "\\>"))
679 (setq count (- count meta-indent-level))) 752 (setq count (- count meta-indent-level))))))
680 ;; Count number of open-close parentheses within line.
681 ((looking-at "(")
682 (setq count (+ count meta-indent-level)))
683 ((looking-at ")")
684 (setq count (- count meta-indent-level)))
685 )))
686 count)))) 753 count))))
687 754
688 755