Commit 5ad4bef5 authored by Stefan Monnier's avatar Stefan Monnier
Browse files

Provide a simple generic indentation engine and use it for Prolog.

* emacs-lisp/smie.el: New file.
* progmodes/prolog.el (prolog-smie-op-levels)
(prolog-smie-indent-rules): New var.
(prolog-mode-variables): Use them to configure SMIE.
(prolog-indent-line, prolog-indent-level): Remove.
parent 16455a85
......@@ -210,6 +210,8 @@ threads simultaneously.
* New Modes and Packages in Emacs 24.1
** smie.el is a package providing a simple generic indentation engine.
** secrets.el is an implementation of the Secret Service API, an
interface to password managers like GNOME Keyring or KDE Wallet. The
Secret Service API requires D-Bus for communication.
......
2010-05-17 Stefan Monnier <monnier@iro.umontreal.ca>
Provide a simple generic indentation engine and use it for Prolog.
* emacs-lisp/smie.el: New file.
* progmodes/prolog.el (prolog-smie-op-levels)
(prolog-smie-indent-rules): New var.
(prolog-mode-variables): Use them to configure SMIE.
(prolog-indent-line, prolog-indent-level): Remove.
2010-05-17 Jay Belanger <jay.p.belanger@gmail.com>
* calc/calc-vec.el (math-vector-avg): Put the vector elements in
......@@ -6,7 +15,7 @@
2010-05-16 Jay Belanger <jay.p.belanger@gmail.com>
* calc/calc-vec.el (calc-histogram):
(calcFunc-histogram): Allow vectors as inputs.
(calcFunc-histogram): Allow vectors as inputs.
(math-vector-avg): New function.
* calc/calc-ext.el (math-group-float): Have the number of digits
......
This diff is collapsed.
......@@ -98,6 +98,61 @@ When nil, send actual operating system end of file."
(defvar prolog-mode-abbrev-table nil)
(define-abbrev-table 'prolog-mode-abbrev-table ())
(defconst prolog-smie-op-levels
;; Rather than construct the operator levels table from the BNF,
;; we directly provide the operator precedences from GNU Prolog's
;; manual. The only problem is that GNU Prolog's manual uses
;; precedence levels in the opposite sense (higher numbers bind less
;; tightly) than SMIE, so we use negative numbers.
'(("." -10000 -10000)
(":-" -1200 -1200)
("-->" -1200 -1200)
(";" -1100 -1100)
("->" -1050 -1050)
("," -1000 -1000)
("\\+" -900 -900)
("=" -700 -700)
("\\=" -700 -700)
("=.." -700 -700)
("==" -700 -700)
("\\==" -700 -700)
("@<" -700 -700)
("@=<" -700 -700)
("@>" -700 -700)
("@>=" -700 -700)
("is" -700 -700)
("=:=" -700 -700)
("=\\=" -700 -700)
("<" -700 -700)
("=<" -700 -700)
(">" -700 -700)
(">=" -700 -700)
(":" -600 -600)
("+" -500 -500)
("-" -500 -500)
("/\\" -500 -500)
("\\/" -500 -500)
("*" -400 -400)
("/" -400 -400)
("//" -400 -400)
("rem" -400 -400)
("mod" -400 -400)
("<<" -400 -400)
(">>" -400 -400)
("**" -200 -200)
("^" -200 -200)
;; Prefix
;; ("+" 200 200)
;; ("-" 200 200)
;; ("\\" 200 200)
)
"Precedence levels of infix operators.")
(defconst prolog-smie-indent-rules
'((":-")
("->"))
"Prolog indentation rules.")
(defun prolog-mode-variables ()
(make-local-variable 'paragraph-separate)
(setq paragraph-separate (concat "%%\\|$\\|" page-delimiter)) ;'%%..'
......@@ -105,8 +160,10 @@ When nil, send actual operating system end of file."
(setq paragraph-ignore-fill-prefix t)
(make-local-variable 'imenu-generic-expression)
(setq imenu-generic-expression '((nil "^\\sw+" 0)))
(make-local-variable 'indent-line-function)
(setq indent-line-function 'prolog-indent-line)
(smie-setup prolog-smie-op-levels prolog-smie-indent-rules)
(set (make-local-variable 'forward-sexp-function)
'smie-forward-sexp-command)
(set (make-local-variable 'smie-indent-basic) prolog-indent-width)
(make-local-variable 'comment-start)
(setq comment-start "%")
(make-local-variable 'comment-start-skip)
......@@ -149,65 +206,6 @@ if that value is non-nil."
nil nil nil
beginning-of-line)))
(defun prolog-indent-line ()
"Indent current line as Prolog code.
With argument, indent any additional lines of the same clause
rigidly along with this one (not yet)."
(interactive "p")
(let ((indent (prolog-indent-level))
(pos (- (point-max) (point))))
(beginning-of-line)
(indent-line-to indent)
(if (> (- (point-max) pos) (point))
(goto-char (- (point-max) pos)))))
(defun prolog-indent-level ()
"Compute Prolog indentation level."
(save-excursion
(beginning-of-line)
(skip-chars-forward " \t")
(cond
((looking-at "%%%") 0) ;Large comment starts
((looking-at "%[^%]") comment-column) ;Small comment starts
((bobp) 0) ;Beginning of buffer
(t
(let ((empty t) ind more less)
(if (looking-at ")")
(setq less t) ;Find close
(setq less nil))
;; See previous indentation
(while empty
(forward-line -1)
(beginning-of-line)
(if (bobp)
(setq empty nil)
(skip-chars-forward " \t")
(if (not (or (looking-at "%[^%]") (looking-at "\n")))
(setq empty nil))))
(if (bobp)
(setq ind 0) ;Beginning of buffer
(setq ind (current-column))) ;Beginning of clause
;; See its beginning
(if (looking-at "%%[^%]")
ind
;; Real prolog code
(if (looking-at "(")
(setq more t) ;Find open
(setq more nil))
;; See its tail
(end-of-prolog-clause)
(or (bobp) (forward-char -1))
(cond ((looking-at "[,(;>]")
(if (and more (looking-at "[^,]"))
(+ ind prolog-indent-width) ;More indentation
(max tab-width ind))) ;Same indentation
((looking-at "-") tab-width) ;TAB
((or less (looking-at "[^.]"))
(max (- ind prolog-indent-width) 0)) ;Less indentation
(t 0)) ;No indentation
)))
)))
(defun end-of-prolog-clause ()
"Go to end of clause in this line."
(beginning-of-line 1)
......
......@@ -2077,7 +2077,11 @@ to `shell-command-history'."
Like `shell-command' but if COMMAND doesn't end in ampersand, adds `&'
surrounded by whitespace and executes the command asynchronously.
The output appears in the buffer `*Async Shell Command*'."
The output appears in the buffer `*Async Shell Command*'.
In Elisp, you will often be better served by calling `start-process'
directly, since it offers more control and does not impose the use of a
shell (with its need to quote arguments)."
(interactive
(list
(read-shell-command "Async shell command: " nil nil
......@@ -2138,7 +2142,11 @@ If the optional third argument ERROR-BUFFER is non-nil, it is a buffer
or buffer name to which to direct the command's standard error output.
If it is nil, error output is mingled with regular output.
In an interactive call, the variable `shell-command-default-error-buffer'
specifies the value of ERROR-BUFFER."
specifies the value of ERROR-BUFFER.
In Elisp, you will often be better served by calling `call-process' or
`start-process' directly, since it offers more control and does not impose
the use of a shell (with its need to quote arguments)."
(interactive
(list
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment