1 ;; copyright 2003-2005 stefan kersten <steve@k-hornz.de>
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.
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
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
))
27 (format " (default %s):" default
)
28 'fixedcase
'literal prompt
1)
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
))
47 (defun sclang-compress-newlines (&optional buffer
)
48 (with-current-buffer (or buffer
(current-buffer))
50 (goto-char (point-min))
52 (if (and (bolp) (eolp)
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
))
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)
78 ;; (when (equal 0 (call-process "anytopnm" file-name (list (current-buffer) nil)))
81 ;; (buffer-substring-no-properties (point-min) (point-max))
84 (provide 'sclang-util
)