supernova: allocators - fix construct method
[supercollider.git] / editors / scel / el / sclang-util.el
blobea104cbd92227a07c1b11d6b2ce5c8e3e5cc3896
1 ;; copyright 2003-2005 stefan kersten <steve@k-hornz.de>
2 ;;
3 ;; This program is free software; you can redistribute it and/or
4 ;; modify it under the terms of the GNU General Public License as
5 ;; published by the Free Software Foundation; either version 2 of the
6 ;; License, or (at your option) any later version.
7 ;;
8 ;; This program is distributed in the hope that it will be useful, but
9 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
10 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 ;; General Public License for more details.
13 ;; You should have received a copy of the GNU General Public License
14 ;; along with this program; if not, write to the Free Software
15 ;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
16 ;; USA
18 (defun sclang-message (string &rest args)
19 (message "SCLang: %s" (apply 'format string args)))
21 (defun sclang-make-buffer-name (string &optional private-p)
22 (concat (and private-p " ") "*SCLang:" string "*"))
24 (defun sclang-make-prompt-string (prompt default)
25 (if (and default (string-match "\\(:\\)\\s *" prompt))
26 (replace-match
27 (format " (default %s):" default)
28 'fixedcase 'literal prompt 1)
29 prompt))
31 (defun sclang-string-to-int32 (str)
32 "Convert first 4 bytes of str (network byteorder) to 32 bit integer."
33 (logior (lsh (logand (aref str 0) #XFF) 24)
34 (lsh (logand (aref str 1) #XFF) 16)
35 (lsh (logand (aref str 2) #XFF) 8)
36 (logand (aref str 3) #XFF)))
38 (defun sclang-int32-to-string (n)
39 "Convert 32 bit integer n to 4 byte string (network byte order)."
40 (let ((str (make-string 4 0)))
41 (aset str 0 (logand (lsh n -24) #XFF))
42 (aset str 1 (logand (lsh n -16) #XFF))
43 (aset str 2 (logand (lsh n -8) #XFF))
44 (aset str 3 (logand n #XFF))
45 str))
47 (defun sclang-compress-newlines (&optional buffer)
48 (with-current-buffer (or buffer (current-buffer))
49 (save-excursion
50 (goto-char (point-min))
51 (while (not (eobp))
52 (if (and (bolp) (eolp)
53 (save-excursion
54 (forward-line -1)
55 (and (bolp) (eolp))))
56 (delete-char 1)
57 (forward-line 1))))))
59 (eval-when-compile
60 (defmacro sclang-save-buffer-state (varlist &rest body)
61 "Bind variables according to VARLIST and eval BODY restoring buffer state."
62 `(let* ,(append varlist
63 '((modified (buffer-modified-p)) (buffer-undo-list t)
64 (inhibit-read-only t) (inhibit-point-motion-hooks t)
65 (inhibit-modification-hooks t)
66 deactivate-mark buffer-file-name buffer-file-truename))
67 (unwind-protect
68 ,@body
69 (when (and (not modified) (buffer-modified-p))
70 (set-buffer-modified-p nil))))))
72 ;; (defun sclang-create-image (file-name &rest props)
73 ;; (when (file-exists-p file-name)
74 ;; (let ((coding-system-for-read 'no-conversion)
75 ;; (coding-system-for-write 'no-conversion)
76 ;; (inhibit-quit t))
77 ;; (with-temp-buffer
78 ;; (when (equal 0 (call-process "anytopnm" file-name (list (current-buffer) nil)))
79 ;; (apply
80 ;; 'create-image
81 ;; (buffer-substring-no-properties (point-min) (point-max))
82 ;; nil t props))))))
84 (provide 'sclang-util)
86 ;; EOF