caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Till Varoquaux" <till.varoquaux@gmail.com>
To: "Mike Lin" <mikelin@mit.edu>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] ocaml+twt 0.85
Date: Tue, 25 Jul 2006 02:10:04 +0200	[thread overview]
Message-ID: <9d3ec8300607241710k6c05eb89t78b1687b7ae38e47@mail.gmail.com> (raw)
In-Reply-To: <2a1a1a0c0607241639x7272d1aeoc88ddec8912f9715@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1221 bytes --]

I did a quick hack to Tuareg to get indentation working in python-mode
like way. You will find the el file here enclosed.

To autoload I use the following (warning to lisp lovers: this is very
ugly, I'm just getting started with elisp).

(autoload 'tuareg-mode "tuareg" "Major mode for editing Caml code" t)
(autoload 'caml+twt-mode "caml+twt" "Major mode for editing Caml+twt code" t)

(defun start-mlmode ()
    (when
        (save-excursion
          (progn
            (goto-char (point-min))
            (looking-at "(\\*pp ocaml\\+twt\\*)[:blank:]*")
            )
          )
      (caml+twt-mode)
      ;;(tuareg-mode)
      )
      (remove-hook 'find-file-hook 'start-mlmode 1)
    )

(add-hook 'tuareg-load-hook ( lambda ()(add-hook 'find-file-hook
'start-mlmode 1))

Which will switch over to caml+twt mode on opening a file with a .ml
extension only if the first line is:

(*pp ocaml+twt*)

(this is consistent with OCamlMakefile).
Syntax highlighting of comments doesn't work anymore.
Hope this turns out usefull to someone.
Till

P.S. Mike, I sent you a mail about this mode a while back but I never
got an answer. If some lisp addict could clean it up I think it should
go in the distribtion of ocaml+twt.

[-- Attachment #2: caml+twt.el --]
[-- Type: text/x-emacs-lisp, Size: 1878 bytes --]

;; Alist of possible indentations and start of statement they would close.
(defvar caml+twt-indent-list nil
  "Internal use.")
;; Length of the above
(defvar caml+twt-indent-list-length nil
  "Internal use.")
;; Current index into the alist.
(defvar caml+twt-indent-index nil
  "Internal use.")

;;behaves like vim's autoindent
(defun caml+twt-indent-line-1 ()
  (let ((target 
	 (save-excursion
	   (beginning-of-line)
	   (if (bobp)
	       ;;If this is the first line then it should be set to 0
	       0
	     (forward-line -1)
	     ;;Begin navigating to find the first previous non blank line...
	     (while (and (not (bobp)) (looking-at "[:blank:]*\n"))
	       (forward-line -1))
	     (current-indentation)
	     )
	   )))
	 (beginning-of-line)
	 (delete-horizontal-space)
	 (indent-to target))
  )

;;Ripped of python.el 
(defun caml+twt-indentation-levels ()
  (list (+ 2 (current-indentation)) 
	(current-indentation))
)

(defun caml+twt-indent-line ()
  (interactive)
  (if (eq last-command this-command)
      (progn (setq caml+twt-indent-index (% (1+ caml+twt-indent-index)
					     caml+twt-indent-list-length))
	     (beginning-of-line)
	     (delete-horizontal-space)
	     (indent-to (nth caml+twt-indent-index caml+twt-indent-list))
	     )
    (caml+twt-indent-line-1)
    (setq caml+twt-indent-list (caml+twt-indentation-levels)
	  caml+twt-indent-list-length (length caml+twt-indent-list)
	  caml+twt-indent-index (1- caml+twt-indent-list-length))))


(define-derived-mode caml+twt-mode tuareg-mode "tuareg+twt mode"
 (setq indent-line-function 'caml+twt-indent-line)
 (setq indent-tabs-mode 'nil)
 (run-hooks 'caml+twt-mode-hook)
 )

(defun caml+twt-help () (interactive)
  (describe-function 'caml+twt-mode))

;;error translating with macros?
;;Maybe defadvice
;;http://www.bookshelf.jp/texi/onlisp/onlisp_8.html#SEC53
;;
;;

(provide 'caml+twt-mode)

  reply	other threads:[~2006-07-25  0:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-24 23:39 Mike Lin
2006-07-25  0:10 ` Till Varoquaux [this message]
2006-08-04 23:09 ` Ingo Bormuth

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=9d3ec8300607241710k6c05eb89t78b1687b7ae38e47@mail.gmail.com \
    --to=till.varoquaux@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=mikelin@mit.edu \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).