Version française
Home     About     Download     Resources     Contact us    
Browse thread
ocaml+twt v0.81
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Till Varoquaux <till.varoquaux@g...>
Subject: Re: [Caml-list] ocaml+twt v0.81
Thank you for this great utility!

I'd like to know what emac configuration users have. Hopefully we can
work towards a good sample file which could be included in the
distribution. Currently I use:

;;behaves like vim's autoindent
(defun caml+twt-calculate-indentation ()
     (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)
       )
       ))

;;Ripped of python.el hopefully we will be able to circle through tab
indentation
;;level someday
(defun caml+twt-indent-line ()
  (let ((target (caml+twt-calculate-indentation))
	(pos (- (point-max) (point))))
    (if (= target (current-indentation))
	(if (< (current-column) (current-indentation))
	    (back-to-indentation))
      (beginning-of-line)
      (delete-horizontal-space)
      (indent-to target)
      (if (> (- (point-max) pos) (point))
	  (goto-char (- (point-max) pos))))))

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

;;(autoload 'caml+twt-mode "caml+twt" "Major mode for editing Ocaml+twt code" t)
(add-to-list 'auto-mode-alist '("\\.twt" . caml+twt-mode))

Cheers,
Till Varoquaux

P.S.: please be tolerant these are my first elisp lines ever...