all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: michael@cadilhac.name (Michaël Cadilhac)
To: emacs-devel@gnu.org
Subject: Indentation in the METAPOST mode.
Date: Thu, 09 Aug 2007 03:00:39 +0200	[thread overview]
Message-ID: <87y7gl7c94.fsf@lrde.org> (raw)


[-- Attachment #1.1.1: Type: text/plain, Size: 619 bytes --]

Hi guys, long time no see !

Indentation in the METAPOST mode has, IMO, two major flaws :

1. A bug. If the buffer starts with beginfig, the contents of the figure
is not properly indented (it stays on the first column).

2. When wrapping an expression on several lines, the indentation is the
same for each line, this is bad style : I'd prefer

beginfig(1)
  draw (0,0)--(1,2)--(10,3)--
    (0,1)--(10,3);
  draw (2,2);
endfig

I propose the following patch which considers that keywords like
beginfig does not need ending semicolon (it's /quite/ the case).

Tell me if it's worth installing it.


[-- Attachment #1.1.2: meta-mode.patch --]
[-- Type: text/x-patch, Size: 5488 bytes --]

Index: lisp/progmodes/meta-mode.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/progmodes/meta-mode.el,v
retrieving revision 1.19
diff -c -r1.19 meta-mode.el
*** lisp/progmodes/meta-mode.el	26 Jul 2007 05:27:28 -0000	1.19
--- lisp/progmodes/meta-mode.el	9 Aug 2007 00:51:47 -0000
***************
*** 620,625 ****
--- 620,628 ----
       ((and meta-ignore-comment-regexp
             (looking-at meta-ignore-comment-regexp))
        (current-indentation))
+      ;; Beginning of buffer.
+      ((eq (point-at-bol) (point-min))
+       0)
       ;; Backindent at end of environments.
       ((looking-at
         (concat "\\<" meta-end-environment-regexp "\\>"))
***************
*** 631,661 ****
       (t (meta-indent-calculate-last)))))
  
  (defun meta-indent-calculate-last ()
!   "Return the indentation of previous line of Metafont or MetaPost source."
    (save-restriction
      (widen)
      (skip-chars-backward "\n\t ")
!     (move-to-column (current-indentation))
!     ;; Ignore comments.
!     (while (and (looking-at comment-start) (not (bobp)))
!       (skip-chars-backward "\n\t ")
!       (if (not (bobp))
!           (move-to-column (current-indentation))))
!     (cond
!      ((bobp) 0)
!      (t (+ (current-indentation)
!            (meta-indent-level-count)
!            (cond
!             ;; Compensate for backindent at end of environments.
!             ((looking-at
!               (concat "\\<"meta-end-environment-regexp "\\>"))
!              meta-indent-level)
!             ;; Compensate for backindent within environments.
!             ((looking-at
!               (concat "\\<" meta-within-environment-regexp "\\>"))
!              meta-indent-level)
!             (t 0)))))
!     ))
  
  (defun meta-indent-level-count ()
    "Count indentation change for begin-end commands in the current line."
--- 634,700 ----
       (t (meta-indent-calculate-last)))))
  
  (defun meta-indent-calculate-last ()
!   "Return the indentation of previous line of Metafont or MetaPost source.
! If the current line is a continuation, i.e. the previous line doesn't end
! up with a semicolon, add some more indentation."
    (save-restriction
      (widen)
+     (meta-indent-previous-line)
+     (+ (current-indentation)
+        (meta-indent-level-count)
+        (let ((unfinished (meta-indent-unfinished-line-p)))
+ 	 (cond ((eq unfinished t) meta-indent-level)
+ 	       ((and (not unfinished)
+ 		     (save-excursion
+ 		       (meta-indent-previous-line)
+ 		       (meta-indent-unfinished-line-p)))
+ 		;; Compensate a previous continuation indentation.
+ 		(- meta-indent-level))
+ 	       (t 0)))
+        (cond
+ 	;; Compensate for backindent at end of environments.
+ 	((looking-at
+ 	  (concat "\\<" meta-end-environment-regexp "\\>"))
+ 	 meta-indent-level)
+ 	;; Compensate for backindent within environments.
+ 	((looking-at
+ 	  (concat "\\<" meta-within-environment-regexp "\\>"))
+ 	 meta-indent-level)
+ 	(t 0)))))
+ 
+ (defun meta-indent-previous-line ()
+   "Go to the previous line of code, skipping comments."
+   (skip-chars-backward "\n\t ")
+   (move-to-column (current-indentation))
+   ;; Ignore comments.
+   (while (and (looking-at comment-start) (not (bobp)))
      (skip-chars-backward "\n\t ")
!     (if (not (bobp))
! 	(move-to-column (current-indentation)))))
! 
! (defun meta-indent-unfinished-line-p ()
!   "Tell if the current line of code ends with an unfinished expression.
! Return t if the line is the first line of the unfinished expression.
! Return 'continued if the line is a continuation.
! Return nil if the line is a finished one."
!   (save-excursion
!     (end-of-line)
!     (if (search-backward ";" (point-at-bol) t)
! 	(forward-char)
!       (beginning-of-line))
!     ;; See if the last statement of the line is environment-related,
!     ;; or exists at all.
!     (if (looking-at (concat "[ \t]*\\($\\|" (regexp-quote comment-start)
! 			    "\\|\\<" meta-end-environment-regexp "\\>"
! 			    "\\|\\<" meta-begin-environment-regexp "\\>"
! 			    "\\|\\<" meta-within-environment-regexp "\\>\\)"))
! 	nil
!       (if (or (bobp) (/= (point-at-bol) (point)))
! 	  t
! 	;; Otherwise, if there was no semicolon on the line, see if
! 	;; the previous line was a continuation.
! 	(meta-indent-previous-line)
! 	(if (meta-indent-unfinished-line-p) 'continued t)))))
  
  (defun meta-indent-level-count ()
    "Count indentation change for begin-end commands in the current line."
Index: lisp/ChangeLog
===================================================================
RCS file: /sources/emacs/emacs/lisp/ChangeLog,v
retrieving revision 1.11534
diff -C 0 -r1.11534 ChangeLog
*** lisp/ChangeLog	8 Aug 2007 16:38:31 -0000	1.11534
--- lisp/ChangeLog	9 Aug 2007 00:52:04 -0000
***************
*** 0 ****
--- 1,12 ----
+ 2007-08-09  Michaël Cadilhac  <michael@cadilhac.name>
+ 
+ 	* progmodes/meta-mode.el (meta-indent-calculate): Force
+ 	indentation at bop to 0.
+ 	(meta-indent-previous-line): New.  Go to the previous line of code
+ 	by skipping comments backward.
+ 	(meta-indent-unfinished-line-p): New.  Tell if the current line is
+ 	unfinished, i.e. contains an expression that will be ended in a
+ 	future line.
+ 	(meta-indent-calculate-last): Use it to add some more indentation
+ 	when continuing a line.
+ 

[-- Attachment #1.1.3: Type: text/plain, Size: 327 bytes --]


-- 
 |   Michaël `Micha' Cadilhac       |    Le copillage-collage                |
 |   http://michael.cadilhac.name   |       tue le programmeur.              |
 |   JID/MSN:                       |           -- Dictons LRDE              |
 `----  michael.cadilhac@gmail.com  |                                   -  --'

[-- Attachment #1.2: Type: application/pgp-signature, Size: 188 bytes --]

[-- Attachment #2: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

             reply	other threads:[~2007-08-09  1:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-09  1:00 Michaël Cadilhac [this message]
2007-08-09  7:05 ` Indentation in the METAPOST mode Leo
2007-08-09  9:50 ` Michaël Cadilhac
2007-08-09 13:22 ` Michaël Cadilhac
2007-08-09 23:11 ` Richard Stallman
2007-09-10 12:49   ` Leo
2007-09-10 17:11   ` Leo
2007-09-10 17:31     ` Michaël Cadilhac
2007-09-10 17:39       ` Leo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y7gl7c94.fsf@lrde.org \
    --to=michael@cadilhac.name \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.