3 --- constants/constants.el.orig 2015-12-26 17:44:31.734520833 +0100
4 +++ constants/constants.el 2015-12-30 17:41:28.402871263 +0100
7 (eval-when-compile (defvar ctable))
9 +(defun constants-is-lisp-like (mode)
11 + (string-match "\\(lisp\\|scheme\\)" (symbol-name mode))))
13 +(defun constants-is-set-like ()
18 + (or (looking-at "(set[qf!]?\\>") (looking-at "(define\\>"))))
19 + (error nil)))) ; return value nil means use default
22 +(defun constants-lisp-like-function ()
23 + "Check context for constants insertion."
24 + (if (constants-is-set-like)
25 + '(emacs-lisp-mode "%n %v%t; %d %u" "e" "(* %p %v)")
26 + '(emacs-lisp-mode "(%n %v)%t; %d %u" "e" "(* %p %v)")))
29 +(mapc (lambda (mode-hook)
32 + (setq constants-language-function
33 + 'constants-lisp-like-function))))
34 + '(scheme-mode-hook emacs-lisp-mode-hook lisp-mode-hook))
37 (defun constants-insert (&optional unit-system names)
38 "Insert one or more natural constant definitions in source code.
40 (funcall process-func ins))
41 ;; Here comes the insertion stuff for source code editing modes.
42 ;; First make sure we start a new line
44 - "\\S-" (buffer-substring (point-at-bol) (point-at-eol)))
45 + (if (and (string-match
46 + "\\S-" (buffer-substring (point-at-bol) (point-at-eol)))
47 + (not (constants-is-lisp-like mode)))
48 ;; non-empty line, insert after this line
52 (if (string-match "\\(.*\\)%t\\(.*\\)" line)
53 (let ((comment-column 42))
54 (insert (match-string 1 line))
55 - (indent-to comment-column)
56 - (insert (match-string 2 line)))
57 + (if (and (constants-is-lisp-like mode)
58 + (or (constants-is-set-like)
62 + (move-to-column comment-column t)
63 + (insert (match-string 2 line))
64 + ;; insert a newline such that paredit's M-) can mode
65 + ;; the closing parentheses to the next line.
66 + (newline-and-indent)))
68 + (indent-to comment-column)
69 + (insert (match-string 2 line)))))
71 - (if constants-indent-code
72 - (newline-and-indent)
75 + (unless (and (constants-is-lisp-like mode) (null clist))
76 + (if constants-indent-code
77 + (newline-and-indent)
80 (defun constants-get (&optional const message)
81 "Return the value of CONST as defined in the constants package.