Commit 650cff3d authored by Stefan Monnier's avatar Stefan Monnier
Browse files

* lisp/emacs-lisp/smie.el (smie-auto-fill): Rework to be more robust.

(smie-setup): Use add-function to set it.

* lisp/progmodes/octave.el (octave-smie-rules): Return nil rather than
0 after a semi-colon; it works better for smie-auto-fill.
(octave--indent-new-comment-line): New function.
(octave-indent-new-comment-line): Use it (indirectly).
(octave-mode): Don't disable smie-auto-fill.  Use add-function to
modify comment-line-break-function.
parent 9631677d
2013-05-24 Stefan Monnier <monnier@iro.umontreal.ca>
* progmodes/octave.el (octave-smie-rules): Return nil rather than
0 after a semi-colon; it works better for smie-auto-fill.
(octave--indent-new-comment-line): New function.
(octave-indent-new-comment-line): Use it (indirectly).
(octave-mode): Don't disable smie-auto-fill. Use add-function to
modify comment-line-break-function.
* emacs-lisp/smie.el (smie-auto-fill): Rework to be more robust.
(smie-setup): Use add-function to set it.
2013-05-24 Sam Steingold <sds@gnu.org> 2013-05-24 Sam Steingold <sds@gnu.org>
   
* sort.el (delete-duplicate-lines): Accept an optional `keep-blanks' * sort.el (delete-duplicate-lines): Accept an optional `keep-blanks'
......
...@@ -1735,37 +1735,45 @@ to which that point should be aligned, if we were to reindent it.") ...@@ -1735,37 +1735,45 @@ to which that point should be aligned, if we were to reindent it.")
(save-excursion (indent-line-to indent)) (save-excursion (indent-line-to indent))
(indent-line-to indent))))) (indent-line-to indent)))))
(defun smie-auto-fill () (defun smie-auto-fill (do-auto-fill)
(let ((fc (current-fill-column))) (let ((fc (current-fill-column)))
(while (and fc (> (current-column) fc)) (when (and fc (> (current-column) fc))
(or (unless (or (nth 8 (save-excursion ;; The loop below presumes BOL is outside of strings or comments. Also,
(syntax-ppss (line-beginning-position)))) ;; sometimes we prefer to fill the comment than the code around it.
(nth 8 (syntax-ppss))) (unless (or (nth 8 (save-excursion
(save-excursion (syntax-ppss (line-beginning-position))))
(let ((end (point)) (nth 4 (save-excursion
(bsf (progn (beginning-of-line) (move-to-column fc)
(syntax-ppss))))
(while
(and (with-demoted-errors
(save-excursion
(let ((end (point))
(bsf nil) ;Best-so-far.
(gain 0))
(beginning-of-line)
(while (progn
(smie-indent-forward-token) (smie-indent-forward-token)
(point))) (and (<= (point) end)
(gain 0) (<= (current-column) fc)))
curcol) ;; FIXME? `smie-indent-calculate' can (and often
(while (and (<= (point) end) ;; does) return a result that actually depends on the
(<= (setq curcol (current-column)) fc)) ;; presence/absence of a newline, so the gain computed
;; FIXME? `smie-indent-calculate' can (and often will) ;; here may not be accurate, but in practice it seems
;; return a result that actually depends on the ;; to work well enough.
;; presence/absence of a newline, so the gain computed here (skip-chars-forward " \t")
;; may not be accurate, but in practice it seems to works (let* ((newcol (smie-indent-calculate))
;; well enough. (newgain (- (current-column) newcol)))
(let* ((newcol (smie-indent-calculate)) (when (> newgain gain)
(newgain (- curcol newcol))) (setq gain newgain)
(when (> newgain gain) (setq bsf (point)))))
(setq gain newgain) (when (> gain 0)
(setq bsf (point)))) (goto-char bsf)
(smie-indent-forward-token)) (newline-and-indent)
(when (> gain 0) 'done))))
(goto-char bsf) (> (current-column) fc))))
(newline-and-indent) (when (> (current-column) fc)
'done)))) (funcall do-auto-fill)))))
(do-auto-fill)))))
(defun smie-setup (grammar rules-function &rest keywords) (defun smie-setup (grammar rules-function &rest keywords)
...@@ -1775,12 +1783,11 @@ RULES-FUNCTION is a set of indentation rules for use on `smie-rules-function'. ...@@ -1775,12 +1783,11 @@ RULES-FUNCTION is a set of indentation rules for use on `smie-rules-function'.
KEYWORDS are additional arguments, which can use the following keywords: KEYWORDS are additional arguments, which can use the following keywords:
- :forward-token FUN - :forward-token FUN
- :backward-token FUN" - :backward-token FUN"
(set (make-local-variable 'smie-rules-function) rules-function) (setq-local smie-rules-function rules-function)
(set (make-local-variable 'smie-grammar) grammar) (setq-local smie-grammar grammar)
(set (make-local-variable 'indent-line-function) 'smie-indent-line) (setq-local indent-line-function #'smie-indent-line)
(set (make-local-variable 'normal-auto-fill-function) 'smie-auto-fill) (add-function :around (local 'normal-auto-fill-function) #'smie-auto-fill)
(set (make-local-variable 'forward-sexp-function) (setq-local forward-sexp-function #'smie-forward-sexp-command)
'smie-forward-sexp-command)
(while keywords (while keywords
(let ((k (pop keywords)) (let ((k (pop keywords))
(v (pop keywords))) (v (pop keywords)))
...@@ -1792,30 +1799,26 @@ KEYWORDS are additional arguments, which can use the following keywords: ...@@ -1792,30 +1799,26 @@ KEYWORDS are additional arguments, which can use the following keywords:
(_ (message "smie-setup: ignoring unknown keyword %s" k))))) (_ (message "smie-setup: ignoring unknown keyword %s" k)))))
(let ((ca (cdr (assq :smie-closer-alist grammar)))) (let ((ca (cdr (assq :smie-closer-alist grammar))))
(when ca (when ca
(set (make-local-variable 'smie-closer-alist) ca) (setq-local smie-closer-alist ca)
;; Only needed for interactive calls to blink-matching-open. ;; Only needed for interactive calls to blink-matching-open.
(set (make-local-variable 'blink-matching-check-function) (setq-local blink-matching-check-function #'smie-blink-matching-check)
#'smie-blink-matching-check)
(unless smie-highlight-matching-block-mode (unless smie-highlight-matching-block-mode
(add-hook 'post-self-insert-hook (add-hook 'post-self-insert-hook
#'smie-blink-matching-open 'append 'local)) #'smie-blink-matching-open 'append 'local))
(set (make-local-variable 'smie-blink-matching-triggers) ;; Setup smie-blink-matching-triggers. Rather than wait for SPC to
(append smie-blink-matching-triggers ;; blink, try to blink as soon as we type the last char of a block ender.
;; Rather than wait for SPC to blink, try to blink as (let ((closers (sort (mapcar #'cdr smie-closer-alist) #'string-lessp))
;; soon as we type the last char of a block ender. (triggers ())
(let ((closers (sort (mapcar #'cdr smie-closer-alist) closer)
#'string-lessp)) (while (setq closer (pop closers))
(triggers ()) (unless
closer) ;; FIXME: this eliminates prefixes of other closers, but we
(while (setq closer (pop closers)) ;; should probably eliminate prefixes of other keywords as well.
(unless (and closers (and closers (string-prefix-p closer (car closers)))
;; FIXME: this eliminates prefixes of other (push (aref closer (1- (length closer))) triggers)))
;; closers, but we should probably (setq-local smie-blink-matching-triggers
;; eliminate prefixes of other keywords (append smie-blink-matching-triggers
;; as well. (delete-dups triggers)))))))
(string-prefix-p closer (car closers)))
(push (aref closer (1- (length closer))) triggers)))
(delete-dups triggers)))))))
(provide 'smie) (provide 'smie)
......
...@@ -438,7 +438,7 @@ Non-nil means always go to the next Octave code line after sending." ...@@ -438,7 +438,7 @@ Non-nil means always go to the next Octave code line after sending."
(smie-rule-parent octave-block-offset) (smie-rule-parent octave-block-offset)
;; For (invalid) code between switch and case. ;; For (invalid) code between switch and case.
;; (if (smie-parent-p "switch") 4) ;; (if (smie-parent-p "switch") 4)
0)))) nil))))
(defun octave-indent-comment () (defun octave-indent-comment ()
"A function for `smie-indent-functions' (which see)." "A function for `smie-indent-functions' (which see)."
...@@ -552,11 +552,10 @@ definitions can also be stored in files and used in batch mode." ...@@ -552,11 +552,10 @@ definitions can also be stored in files and used in batch mode."
(setq-local paragraph-ignore-fill-prefix t) (setq-local paragraph-ignore-fill-prefix t)
(setq-local fill-paragraph-function 'octave-fill-paragraph) (setq-local fill-paragraph-function 'octave-fill-paragraph)
;; Use `smie-auto-fill' after fixing bug#14381.
(setq-local normal-auto-fill-function 'do-auto-fill)
(setq-local fill-nobreak-predicate (setq-local fill-nobreak-predicate
(lambda () (eq (octave-in-string-p) ?'))) (lambda () (eq (octave-in-string-p) ?')))
(setq-local comment-line-break-function #'octave-indent-new-comment-line) (add-function :around (local 'comment-line-break-function)
#'octave--indent-new-comment-line)
(setq font-lock-defaults '(octave-font-lock-keywords)) (setq font-lock-defaults '(octave-font-lock-keywords))
...@@ -1112,11 +1111,16 @@ q: Don't fix\n" func file)) ...@@ -1112,11 +1111,16 @@ q: Don't fix\n" func file))
;;; Indentation ;;; Indentation
(defun octave-indent-new-comment-line (&optional soft) (defun octave-indent-new-comment-line (&optional soft)
;; FIXME: C-M-j should probably be bound globally to a function like
;; this one.
"Break Octave line at point, continuing comment if within one. "Break Octave line at point, continuing comment if within one.
Insert `octave-continuation-string' before breaking the line Insert `octave-continuation-string' before breaking the line
unless inside a list. Signal an error if within a single-quoted unless inside a list. Signal an error if within a single-quoted
string." string."
(interactive) (interactive)
(funcall comment-line-break-function soft))
(defun octave--indent-new-comment-line (orig &rest args)
(cond (cond
((octave-in-comment-p) nil) ((octave-in-comment-p) nil)
((eq (octave-in-string-p) ?') ((eq (octave-in-string-p) ?')
...@@ -1128,7 +1132,7 @@ string." ...@@ -1128,7 +1132,7 @@ string."
(unless (and (cadr (syntax-ppss)) (unless (and (cadr (syntax-ppss))
(eq (char-after (cadr (syntax-ppss))) ?\()) (eq (char-after (cadr (syntax-ppss))) ?\())
(insert " " octave-continuation-string)))) (insert " " octave-continuation-string))))
(indent-new-comment-line soft) (apply orig args)
(indent-according-to-mode)) (indent-according-to-mode))
(define-obsolete-function-alias (define-obsolete-function-alias
......
...@@ -1089,13 +1089,13 @@ function uninstall (pkgnames, handle_deps, verbose, local_list, ...@@ -1089,13 +1089,13 @@ function uninstall (pkgnames, handle_deps, verbose, local_list,
while (! feof (fid) || line != -1) while (! feof (fid) || line != -1)
if (! any (! isspace (line)) || line(1) == "#" || any (line == "=")) if (! any (! isspace (line)) || line(1) == "#" || any (line == "="))
## Comments, blank lines or comments about unimplemented ## Comments, blank lines or comments about unimplemented
## functions: do nothing ## functions: do nothing
## FIXME: probably comments and pointers to external functions ## FIXME: probably comments and pointers to external functions
## could be treated better when printing to screen? ## could be treated better when printing to screen?
elseif (! isempty (strfind (line, ">>"))) elseif (! isempty (strfind (line, ">>")))
## Skip package name and description as they are in DESCRIPTION ## Skip package name and description as they are in DESCRIPTION
## already. ## already.
elseif (! isspace (line(1))) elseif (! isspace (line(1)))
## Category. ## Category.
if (! isempty (pkg_idx_struct{cat_num}.functions)) if (! isempty (pkg_idx_struct{cat_num}.functions))
...@@ -1658,7 +1658,7 @@ function verify_directory (dir) ...@@ -1658,7 +1658,7 @@ function verify_directory (dir)
line = fgetl (fid); line = fgetl (fid);
while (line != -1) while (line != -1)
if (line(1) == "#") if (line(1) == "#")
## Comments, do nothing. ## Comments, do nothing.
elseif (isspace(line(1))) elseif (isspace(line(1)))
## Continuation lines ## Continuation lines
if (exist ("keyword", "var") && isfield (desc, keyword)) if (exist ("keyword", "var") && isfield (desc, keyword))
...@@ -1752,9 +1752,9 @@ function verify_directory (dir) ...@@ -1752,9 +1752,9 @@ function verify_directory (dir)
endif endif
version = fix_version (parts{2}); version = fix_version (parts{2});
## If no version is specified for the dependency ## If no version is specified for the dependency
## we say that the version should be greater than ## we say that the version should be greater than
## or equal to "0.0.0". ## or equal to "0.0.0".
else else
package = tolower (strip (dep)); package = tolower (strip (dep));
operator = ">="; operator = ">=";
...@@ -1859,7 +1859,7 @@ function write_index (desc, dir, index_file, global_install) ...@@ -1859,7 +1859,7 @@ function write_index (desc, dir, index_file, global_install)
if (! compare_versions (OCTAVE_VERSION, dep.version, dep.operator)) if (! compare_versions (OCTAVE_VERSION, dep.version, dep.operator))
bad_deps{end+1} = dep; bad_deps{end+1} = dep;
endif endif
## Is the current dependency not Octave? ## Is the current dependency not Octave?
else else
ok = false; ok = false;
for i = 1:length (installed_pkgs_lst) for i = 1:length (installed_pkgs_lst)
...@@ -2025,7 +2025,7 @@ function load_packages (files, handle_deps, local_list, global_list) ...@@ -2025,7 +2025,7 @@ function load_packages (files, handle_deps, local_list, global_list)
## Load all. ## Load all.
if (length (files) == 1 && strcmp (files{1}, "all")) if (length (files) == 1 && strcmp (files{1}, "all"))
idx = [1:length(installed_pkgs_lst)]; idx = [1:length(installed_pkgs_lst)];
## Load auto. ## Load auto.
elseif (length (files) == 1 && strcmp (files{1}, "auto")) elseif (length (files) == 1 && strcmp (files{1}, "auto"))
idx = []; idx = [];
for i = 1:length (installed_pkgs_lst) for i = 1:length (installed_pkgs_lst)
...@@ -2033,7 +2033,7 @@ function load_packages (files, handle_deps, local_list, global_list) ...@@ -2033,7 +2033,7 @@ function load_packages (files, handle_deps, local_list, global_list)
idx (end + 1) = i; idx (end + 1) = i;
endif endif
endfor endfor
## Load package_name1 ... ## Load package_name1 ...
else else
idx = []; idx = [];
for i = 1:length (files) for i = 1:length (files)
...@@ -2100,8 +2100,8 @@ function unload_packages (files, handle_deps, local_list, global_list) ...@@ -2100,8 +2100,8 @@ function unload_packages (files, handle_deps, local_list, global_list)
idx = strcmp (p, d); idx = strcmp (p, d);
if (any (idx)) if (any (idx))
rmpath (d); rmpath (d);
## FIXME: We should also check if we need to remove items from ## FIXME: We should also check if we need to remove items from
## EXEC_PATH. ## EXEC_PATH.
endif endif
endfor endfor
endfunction endfunction
......
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