/usr/share/emacs/site-lisp/ocp-indent.el is in ocp-indent 1.4.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | ;;; ocp-indent.el --- automatic indentation with ocp-indent
;;
;; Copyright 2012-2013 OCamlPro
;; Keywords: ocaml languages
;; URL: http://www.typerex.org/ocp-indent.html
;; All rights reserved.This file is distributed under the terms of the
;; GNU Lesser General Public License version 3.0 with linking
;; exception.
;; TypeRex is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; Lesser GNU General Public License for more details.
;;
;;; Commentary:
;; Description:
;; ocp-indent is a simple tool and library to indent OCaml code.
;; Installation:
;; You need ocp-indent installed on you system to work.
;; Usage:
;; Eval this file to automatically use ocp-indent on caml/tuareg buffers.
;;; Code:
(require 'cl)
(defgroup ocp-indent nil
"ocp-indent OCaml indenter binding configuration"
:group 'languages)
(defcustom ocp-indent-path "ocp-indent"
"*Path to access the ocp-indent command"
:group 'ocp-indent :type '(file))
(defcustom ocp-indent-config nil
"*Ocp-indent config string, as for its --config option.
WARNING: DEPRECATED, this will override any user or project
ocp-indent configuration files"
:group 'ocp-indent
:type '(choice (const nil) (string)))
(defcustom ocp-indent-syntax nil
"*Enabled syntax extensions for ocp-indent (see option --syntax)"
:group 'ocp-indent
:type '(repeat (string)))
(defcustom ocp-indent-allow-tabs nil
"*Allow indent-tabs-mode in ocaml buffers. Not recommended, won't work well."
:group 'ocp-indent
:type '(bool))
(defun ocp-in-indentation-p ()
"Tests whether all characters between beginning of line and point
are blanks."
(save-excursion
(skip-chars-backward " \t")
(bolp)))
(defun ocp-indent-args (start-line end-line)
(append
(list "--numeric"
"--lines" (format "%d-%d" start-line end-line))
(if ocp-indent-config (list "--config" ocp-indent-config) nil)
(reduce (lambda (acc syn) (list* "--syntax" syn acc))
ocp-indent-syntax :initial-value nil)))
(defun ocp-indent-file-to-string (file)
(replace-regexp-in-string
"\n$" ""
(with-temp-buffer (insert-file-contents file)
(buffer-string))))
(defun ocp-indent-region (start end)
(interactive "r")
(let*
((start-line (line-number-at-pos start))
(end-line (line-number-at-pos end))
(errfile (make-temp-name "ocp-indent-error"))
(indents-str
(with-output-to-string
(if (/= 0
(apply 'call-process-region
(point-min) (point-max) ocp-indent-path nil
(list standard-output errfile) nil
(ocp-indent-args start-line end-line)))
(error "Can't indent: %s returned failure" ocp-indent-path))))
(indents (mapcar 'string-to-number (split-string indents-str))))
(when (file-exists-p errfile)
(message (ocp-indent-file-to-string errfile))
(delete-file errfile))
(save-excursion
(goto-char start)
(mapcar
#'(lambda (indent) (indent-line-to indent) (forward-line))
indents))
(when (ocp-in-indentation-p) (back-to-indentation))))
(defun ocp-indent-line ()
(interactive nil)
(ocp-indent-region (point) (point)))
;;;###autoload
(defun ocp-setup-indent ()
(interactive nil)
(unless ocp-indent-allow-tabs (set 'indent-tabs-mode nil))
(set (make-local-variable 'indent-line-function) #'ocp-indent-line)
(set (make-local-variable 'indent-region-function) #'ocp-indent-region))
;;;###autoload
(defun ocp-indent-caml-mode-setup ()
(ocp-setup-indent)
(local-unset-key "\t")) ;; caml-mode rebinds TAB !
(add-hook 'tuareg-mode-hook 'ocp-setup-indent t)
(add-hook 'caml-mode-hook 'ocp-indent-caml-mode-setup t)
(provide 'ocp-indent)
;;; ocp-indent.el ends here
|