aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Morris2012-04-16 20:06:56 -0700
committerGlenn Morris2012-04-16 20:06:56 -0700
commit2311d8e5a62b8b6dd7dde45b4b8059d443e2abac (patch)
tree9e526bc6f88f88c2925e05db797570cbc5ad7ee2
parentfc72b15c777af496e9dcbc240f424135379ba955 (diff)
parent699c782b7668c44d0fa4446331b0590a6d5dac82 (diff)
downloademacs-2311d8e5a62b8b6dd7dde45b4b8059d443e2abac.tar.gz
emacs-2311d8e5a62b8b6dd7dde45b4b8059d443e2abac.zip
Merge from pending; try to fix-up suboptimal ses ChangeLog.
-rw-r--r--lisp/ChangeLog32
-rw-r--r--lisp/emacs-lisp/smie.el33
-rw-r--r--lisp/newcomment.el18
-rw-r--r--lisp/ses.el124
4 files changed, 190 insertions, 17 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 90f48d2ab1e..992fee42c28 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,35 @@
12012-04-17 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * emacs-lisp/smie.el: Provide smarter auto-filling.
4 (smie-auto-fill): New function.
5 (smie-setup): Use it.
6
7 * newcomment.el (comment-choose-indent): Obey comment-inline-offset.
8
92012-04-17 Philipp Haselwarter <philipp.haselwarter@gmx.de> (tiny change)
10
11 * newcomment.el (comment-inline-offset): New custom var (bug#11090).
12 (comment-indent): Use it.
13
142012-04-17 Vincent Belaïche <vincentb1@users.sourceforge.net>
15
16 * ses.el: The overall change is to add cell renaming, that is
17 setting fancy names for cell symbols other than name matching
18 "\\`[A-Z]+[0-9]+\\'" regexp .
19 (ses-localvars): Add ses--renamed-cell-symb-list.
20 (ses-create-cell-variable): New defun.
21 (ses-destroy-cell-variable-range): Respect ses--numrows, ses--numcols.
22 (ses-relocate-formula): Relocate formulas only for cells the
23 symbols of which are not renamed, i.e. symbols whose names do not
24 match regexp "\\`[A-Z]+[0-9]+\\'".
25 (ses-relocate-all): Relocate values only for cells the symbols of
26 which are not renamed.
27 (ses-load): Create cells variables as the (ses-cell ...) are read,
28 in order to check row col consistency with cell symbol name only
29 for cells that are not renamed.
30 (ses-replace-name-in-formula): New defun.
31 (ses-rename-cell): New defun.
32
12012-04-17 Peter Oliver <bzr@mavit.org.uk> (tiny change) 332012-04-17 Peter Oliver <bzr@mavit.org.uk> (tiny change)
2 34
3 * progmodes/perl-mode.el (perl-indent-parens-as-block): 35 * progmodes/perl-mode.el (perl-indent-parens-as-block):
diff --git a/lisp/emacs-lisp/smie.el b/lisp/emacs-lisp/smie.el
index 2a12f03e514..5382e601e67 100644
--- a/lisp/emacs-lisp/smie.el
+++ b/lisp/emacs-lisp/smie.el
@@ -1602,6 +1602,38 @@ to which that point should be aligned, if we were to reindent it.")
1602 (save-excursion (indent-line-to indent)) 1602 (save-excursion (indent-line-to indent))
1603 (indent-line-to indent))))) 1603 (indent-line-to indent)))))
1604 1604
1605(defun smie-auto-fill ()
1606 (let ((fc (current-fill-column))
1607 (try-again nil))
1608 (while (and fc (> (current-column) fc))
1609 (cond
1610 ((not (or (nth 8 (save-excursion
1611 (syntax-ppss (line-beginning-position))))
1612 (nth 8 (syntax-ppss))))
1613 (save-excursion
1614 (beginning-of-line)
1615 (smie-indent-forward-token)
1616 (let ((bsf (point))
1617 (gain 0)
1618 curcol)
1619 (while (<= (setq curcol (current-column)) fc)
1620 ;; FIXME? `smie-indent-calculate' can (and often will)
1621 ;; return a result that actually depends on the presence/absence
1622 ;; of a newline, so the gain computed here may not be accurate,
1623 ;; but in practice it seems to works well enough.
1624 (let* ((newcol (smie-indent-calculate))
1625 (newgain (- curcol newcol)))
1626 (when (> newgain gain)
1627 (setq gain newgain)
1628 (setq bsf (point))))
1629 (smie-indent-forward-token))
1630 (when (> gain 0)
1631 (setq try-again)
1632 (goto-char bsf)
1633 (newline-and-indent)))))
1634 (t (do-auto-fill))))))
1635
1636
1605(defun smie-setup (grammar rules-function &rest keywords) 1637(defun smie-setup (grammar rules-function &rest keywords)
1606 "Setup SMIE navigation and indentation. 1638 "Setup SMIE navigation and indentation.
1607GRAMMAR is a grammar table generated by `smie-prec2->grammar'. 1639GRAMMAR is a grammar table generated by `smie-prec2->grammar'.
@@ -1612,6 +1644,7 @@ KEYWORDS are additional arguments, which can use the following keywords:
1612 (set (make-local-variable 'smie-rules-function) rules-function) 1644 (set (make-local-variable 'smie-rules-function) rules-function)
1613 (set (make-local-variable 'smie-grammar) grammar) 1645 (set (make-local-variable 'smie-grammar) grammar)
1614 (set (make-local-variable 'indent-line-function) 'smie-indent-line) 1646 (set (make-local-variable 'indent-line-function) 'smie-indent-line)
1647 (set (make-local-variable 'normal-auto-fill-function) 'smie-auto-fill)
1615 (set (make-local-variable 'forward-sexp-function) 1648 (set (make-local-variable 'forward-sexp-function)
1616 'smie-forward-sexp-command) 1649 'smie-forward-sexp-command)
1617 (while keywords 1650 (while keywords
diff --git a/lisp/newcomment.el b/lisp/newcomment.el
index 37a76e0309c..0862427c3ba 100644
--- a/lisp/newcomment.el
+++ b/lisp/newcomment.el
@@ -269,6 +269,19 @@ makes the comment easier to read. Default is 1. nil means 0."
269 :type '(choice string integer (const nil)) 269 :type '(choice string integer (const nil))
270 :group 'comment) 270 :group 'comment)
271 271
272(defcustom comment-inline-offset 1
273 "Inline comments have to be preceded by at least this many spaces.
274This is useful when style-conventions require a certain minimal offset.
275Python's PEP8 for example recommends two spaces, so you could do:
276
277\(add-hook 'python-mode-hook
278 (lambda () (set (make-local-variable 'comment-inline-offset) 2)))
279
280See `comment-padding' for whole-line comments."
281 :version "24.2"
282 :type 'integer
283 :group 'comment)
284
272;;;###autoload 285;;;###autoload
273(defcustom comment-multi-line nil 286(defcustom comment-multi-line nil
274 "Non-nil means `comment-indent-new-line' continues comments. 287 "Non-nil means `comment-indent-new-line' continues comments.
@@ -587,7 +600,7 @@ Point is expected to be at the start of the comment."
587 (save-excursion (end-of-line) (current-column))))) 600 (save-excursion (end-of-line) (current-column)))))
588 (other nil) 601 (other nil)
589 (min (save-excursion (skip-chars-backward " \t") 602 (min (save-excursion (skip-chars-backward " \t")
590 (if (bolp) 0 (1+ (current-column)))))) 603 (if (bolp) 0 (+ comment-inline-offset (current-column))))))
591 ;; Fix up the range. 604 ;; Fix up the range.
592 (if (< max min) (setq max min)) 605 (if (< max min) (setq max min))
593 ;; Don't move past the fill column. 606 ;; Don't move past the fill column.
@@ -687,7 +700,8 @@ If CONTINUE is non-nil, use the `comment-continue' markers if any."
687 (save-excursion 700 (save-excursion
688 (skip-chars-backward " \t") 701 (skip-chars-backward " \t")
689 (unless (bolp) 702 (unless (bolp)
690 (setq indent (max indent (1+ (current-column)))))) 703 (setq indent (max indent
704 (+ (current-column) comment-inline-offset)))))
691 ;; If that's different from comment's current position, change it. 705 ;; If that's different from comment's current position, change it.
692 (unless (= (current-column) indent) 706 (unless (= (current-column) indent)
693 (delete-region (point) (progn (skip-chars-backward " \t") (point))) 707 (delete-region (point) (progn (skip-chars-backward " \t") (point)))
diff --git a/lisp/ses.el b/lisp/ses.el
index 0638fc344c7..da18046c953 100644
--- a/lisp/ses.el
+++ b/lisp/ses.el
@@ -282,6 +282,9 @@ default printer and then modify its output.")
282 ses--numcols ses--numrows ses--symbolic-formulas 282 ses--numcols ses--numrows ses--symbolic-formulas
283 ses--data-marker ses--params-marker (ses--Dijkstra-attempt-nb . 0) 283 ses--data-marker ses--params-marker (ses--Dijkstra-attempt-nb . 0)
284 ses--Dijkstra-weight-bound 284 ses--Dijkstra-weight-bound
285 ;; This list is useful to speed-up clean-up of symbols when
286 ;; an area containing renamed cell is deleted.
287 ses--renamed-cell-symb-list
285 ;; Global variables that we override 288 ;; Global variables that we override
286 mode-line-process next-line-add-newlines transient-mark-mode) 289 mode-line-process next-line-add-newlines transient-mark-mode)
287 "Buffer-local variables used by SES.") 290 "Buffer-local variables used by SES.")
@@ -674,6 +677,17 @@ for this spreadsheet."
674 (put sym 'ses-cell (cons xrow xcol)) 677 (put sym 'ses-cell (cons xrow xcol))
675 (make-local-variable sym))))) 678 (make-local-variable sym)))))
676 679
680(defun ses-create-cell-variable (sym row col)
681 "Create a buffer-local variable `SYM' for cell at position (ROW, COL).
682
683SYM is the symbol for that variable, ROW and COL are integers for
684row and column of the cell, with numbering starting from 0.
685
686Return nil in case of failure."
687 (unless (local-variable-p sym)
688 (make-local-variable sym)
689 (put sym 'ses-cell (cons row col))))
690
677;; We do not delete the ses-cell properties for the cell-variables, in 691;; We do not delete the ses-cell properties for the cell-variables, in
678;; case a formula that refers to this cell is in the kill-ring and is 692;; case a formula that refers to this cell is in the kill-ring and is
679;; later pasted back in. 693;; later pasted back in.
@@ -682,7 +696,10 @@ for this spreadsheet."
682 (let (sym) 696 (let (sym)
683 (dotimes (row (1+ (- maxrow minrow))) 697 (dotimes (row (1+ (- maxrow minrow)))
684 (dotimes (col (1+ (- maxcol mincol))) 698 (dotimes (col (1+ (- maxcol mincol)))
685 (setq sym (ses-create-cell-symbol (+ row minrow) (+ col mincol))) 699 (let ((xrow (+ row minrow)) (xcol (+ col mincol)))
700 (setq sym (if (and (< xrow ses--numrows) (< xcol ses--numcols))
701 (ses-cell-symbol xrow xcol)
702 (ses-create-cell-symbol xrow xcol))))
686 (if (boundp sym) 703 (if (boundp sym)
687 (push `(apply ses-set-with-undo ,sym ,(symbol-value sym)) 704 (push `(apply ses-set-with-undo ,sym ,(symbol-value sym))
688 buffer-undo-list)) 705 buffer-undo-list))
@@ -1400,7 +1417,8 @@ removed. Example:
1400Sets `ses-relocate-return' to 'delete if cell-references were removed." 1417Sets `ses-relocate-return' to 'delete if cell-references were removed."
1401 (let (rowcol result) 1418 (let (rowcol result)
1402 (if (or (atom formula) (eq (car formula) 'quote)) 1419 (if (or (atom formula) (eq (car formula) 'quote))
1403 (if (setq rowcol (ses-sym-rowcol formula)) 1420 (if (and (setq rowcol (ses-sym-rowcol formula))
1421 (string-match "\\`[A-Z]+[0-9]+\\'" (symbol-name formula)))
1404 (ses-relocate-symbol formula rowcol 1422 (ses-relocate-symbol formula rowcol
1405 startrow startcol rowincr colincr) 1423 startrow startcol rowincr colincr)
1406 formula) ; Pass through as-is. 1424 formula) ; Pass through as-is.
@@ -1508,14 +1526,15 @@ if the range was altered."
1508the rectangle (MINROW,MINCOL)..(NUMROWS,NUMCOLS) by adding ROWINCR and COLINCR 1526the rectangle (MINROW,MINCOL)..(NUMROWS,NUMCOLS) by adding ROWINCR and COLINCR
1509to each symbol." 1527to each symbol."
1510 (let (reform) 1528 (let (reform)
1511 (let (mycell newval) 1529 (let (mycell newval xrow)
1512 (dotimes-with-progress-reporter 1530 (dotimes-with-progress-reporter
1513 (row ses--numrows) "Relocating formulas..." 1531 (row ses--numrows) "Relocating formulas..."
1514 (dotimes (col ses--numcols) 1532 (dotimes (col ses--numcols)
1515 (setq ses-relocate-return nil 1533 (setq ses-relocate-return nil
1516 mycell (ses-get-cell row col) 1534 mycell (ses-get-cell row col)
1517 newval (ses-relocate-formula (ses-cell-formula mycell) 1535 newval (ses-relocate-formula (ses-cell-formula mycell)
1518 minrow mincol rowincr colincr)) 1536 minrow mincol rowincr colincr)
1537 xrow (- row rowincr))
1519 (ses-set-cell row col 'formula newval) 1538 (ses-set-cell row col 'formula newval)
1520 (if (eq ses-relocate-return 'range) 1539 (if (eq ses-relocate-return 'range)
1521 ;; This cell contains a (ses-range X Y) where a cell has been 1540 ;; This cell contains a (ses-range X Y) where a cell has been
@@ -1531,8 +1550,22 @@ to each symbol."
1531 minrow mincol rowincr colincr)) 1550 minrow mincol rowincr colincr))
1532 (ses-set-cell row col 'references newval) 1551 (ses-set-cell row col 'references newval)
1533 (and (>= row minrow) (>= col mincol) 1552 (and (>= row minrow) (>= col mincol)
1534 (ses-set-cell row col 'symbol 1553 (let ((sym (ses-cell-symbol row col))
1535 (ses-create-cell-symbol row col)))))) 1554 (xcol (- col colincr)))
1555 (if (and
1556 sym
1557 (>= xrow 0)
1558 (>= xcol 0)
1559 (null (eq sym
1560 (ses-create-cell-symbol xrow xcol))))
1561 ;; This is a renamed cell, do not update the cell
1562 ;; name, but just update the coordinate property.
1563 (put sym 'ses-cell (cons row col))
1564 (ses-set-cell row col 'symbol
1565 (setq sym (ses-create-cell-symbol row col)))
1566 (unless (and (boundp sym) (local-variable-p sym))
1567 (set (make-local-variable sym) nil)
1568 (put sym 'ses-cell (cons row col)))))) )))
1536 ;; Relocate the cell values. 1569 ;; Relocate the cell values.
1537 (let (oldval myrow mycol xrow xcol) 1570 (let (oldval myrow mycol xrow xcol)
1538 (cond 1571 (cond
@@ -1545,11 +1578,17 @@ to each symbol."
1545 (setq mycol (+ col mincol) 1578 (setq mycol (+ col mincol)
1546 xrow (- myrow rowincr) 1579 xrow (- myrow rowincr)
1547 xcol (- mycol colincr)) 1580 xcol (- mycol colincr))
1548 (if (and (< xrow ses--numrows) (< xcol ses--numcols)) 1581 (let ((sym (ses-cell-symbol myrow mycol))
1549 (setq oldval (ses-cell-value xrow xcol)) 1582 (xsym (ses-create-cell-symbol xrow xcol)))
1550 ;; Cell is off the end of the array. 1583 ;; Make the value relocation only when if the cell is not
1551 (setq oldval (symbol-value (ses-create-cell-symbol xrow xcol)))) 1584 ;; a renamed cell. Otherwise this is not needed.
1552 (ses-set-cell myrow mycol 'value oldval)))) 1585 (and (eq sym xsym)
1586 (ses-set-cell myrow mycol 'value
1587 (if (and (< xrow ses--numrows) (< xcol ses--numcols))
1588 (ses-cell-value xrow xcol)
1589 ;;Cell is off the end of the array
1590 (symbol-value xsym))))))))
1591
1553 ((and (wholenump rowincr) (wholenump colincr)) 1592 ((and (wholenump rowincr) (wholenump colincr))
1554 ;; Insertion of rows and/or columns. Run the loop backwards. 1593 ;; Insertion of rows and/or columns. Run the loop backwards.
1555 (let ((disty (1- ses--numrows)) 1594 (let ((disty (1- ses--numrows))
@@ -1659,7 +1698,6 @@ Does not execute cell formulas or print functions."
1659 (message "Upgrading from SES-1 file format"))) 1698 (message "Upgrading from SES-1 file format")))
1660 (or (= ses--file-format 2) 1699 (or (= ses--file-format 2)
1661 (error "This file needs a newer version of the SES library code")) 1700 (error "This file needs a newer version of the SES library code"))
1662 (ses-create-cell-variable-range 0 (1- ses--numrows) 0 (1- ses--numcols))
1663 ;; Initialize cell array. 1701 ;; Initialize cell array.
1664 (setq ses--cells (make-vector ses--numrows nil)) 1702 (setq ses--cells (make-vector ses--numrows nil))
1665 (dotimes (row ses--numrows) 1703 (dotimes (row ses--numrows)
@@ -1679,11 +1717,10 @@ Does not execute cell formulas or print functions."
1679 (dotimes (row ses--numrows) 1717 (dotimes (row ses--numrows)
1680 (dotimes (col ses--numcols) 1718 (dotimes (col ses--numcols)
1681 (let* ((x (read (current-buffer))) 1719 (let* ((x (read (current-buffer)))
1682 (rowcol (ses-sym-rowcol (car-safe (cdr-safe x))))) 1720 (sym (car-safe (cdr-safe x))))
1683 (or (and (looking-at "\n") 1721 (or (and (looking-at "\n")
1684 (eq (car-safe x) 'ses-cell) 1722 (eq (car-safe x) 'ses-cell)
1685 (eq row (car rowcol)) 1723 (ses-create-cell-variable sym row col))
1686 (eq col (cdr rowcol)))
1687 (error "Cell-def error")) 1724 (error "Cell-def error"))
1688 (eval x))) 1725 (eval x)))
1689 (or (looking-at "\n\n") 1726 (or (looking-at "\n\n")
@@ -3140,6 +3177,63 @@ highlighted range in the spreadsheet."
3140 (mouse-set-point event) 3177 (mouse-set-point event)
3141 (ses-insert-ses-range)) 3178 (ses-insert-ses-range))
3142 3179
3180(defun ses-replace-name-in-formula (formula old-name new-name)
3181 (let ((new-formula formula))
3182 (unless (and (consp formula)
3183 (eq (car-safe formula) 'quote))
3184 (while formula
3185 (let ((elt (car-safe formula)))
3186 (cond
3187 ((consp elt)
3188 (setcar formula (ses-replace-name-in-formula elt old-name new-name)))
3189 ((and (symbolp elt)
3190 (eq (car-safe formula) old-name))
3191 (setcar formula new-name))))
3192 (setq formula (cdr formula))))
3193 new-formula))
3194
3195(defun ses-rename-cell (new-name)
3196 "Rename current cell."
3197 (interactive "*SEnter new name: ")
3198 (ses-check-curcell)
3199 (or
3200 (and (local-variable-p new-name)
3201 (ses-sym-rowcol new-name)
3202 ;; this test is needed because ses-cell property of deleted cells
3203 ;; is not deleted in case of subsequent undo
3204 (memq new-name ses--renamed-cell-symb-list)
3205 (error "Already a cell name"))
3206 (and (boundp new-name)
3207 (null (yes-or-no-p (format "`%S' is already bound outside this buffer, continue? "
3208 new-name)))
3209 (error "Already a bound cell name")))
3210 (let* ((rowcol (ses-sym-rowcol ses--curcell))
3211 (cell (ses-get-cell (car rowcol) (cdr rowcol))))
3212 (put new-name 'ses-cell rowcol)
3213 (dolist (reference (ses-cell-references (car rowcol) (cdr rowcol)))
3214 (let* ((rowcol (ses-sym-rowcol reference))
3215 (cell (ses-get-cell (car rowcol) (cdr rowcol))))
3216 (ses-cell-set-formula (car rowcol)
3217 (cdr rowcol)
3218 (ses-replace-name-in-formula
3219 (ses-cell-formula cell)
3220 ses--curcell
3221 new-name))))
3222 (push new-name ses--renamed-cell-symb-list)
3223 (set new-name (symbol-value ses--curcell))
3224 (aset cell 0 new-name)
3225 (put ses--curcell 'ses-cell nil)
3226 (makunbound ses--curcell)
3227 (setq ses--curcell new-name)
3228 (let* ((pos (point))
3229 (inhibit-read-only t)
3230 (col (current-column))
3231 (end (save-excursion
3232 (move-to-column (1+ col))
3233 (if (eolp)
3234 (+ pos (ses-col-width col) 1)
3235 (point)))))
3236 (put-text-property pos end 'intangible new-name))) )
3143 3237
3144;;---------------------------------------------------------------------------- 3238;;----------------------------------------------------------------------------
3145;; Checking formulas for safety 3239;; Checking formulas for safety