Merge from trunk
authorStefan Monnier <monnier@iro.umontreal.ca>
Sun, 25 Mar 2012 20:37:21 +0000 (16:37 -0400)
committerStefan Monnier <monnier@iro.umontreal.ca>
Sun, 25 Mar 2012 20:37:21 +0000 (16:37 -0400)
lisp/ChangeLog
lisp/emacs-lisp/smie.el
lisp/newcomment.el
lisp/ses.el

index 59abf19..37b00e4 100644 (file)
@@ -1,3 +1,53 @@
+2012-03-25  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+       * newcomment.el (comment-inline-offset): Don't autoload.
+       (comment-choose-indent): Obey comment-inline-offset.
+
+2012-03-25  Philipp Haselwarter  <philipp.haselwarter@gmx.de>  (tiny change)
+
+       * newcomment.el (comment-inline-offset): New custom var (bug#11090).
+       (comment-indent): Use it.
+
+2012-02-15  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+       * emacs-lisp/smie.el: Provide smarter auto-filling.
+       (smie-auto-fill): New function.
+       (smie-setup): Use it.
+
+2011-12-27  Vincent Belaïche  <vincentb1@users.sourceforge.net>
+
+       * ses.el: The overall change is to add cell renaming, that is
+       setting fancy names for cell symbols other than name matching
+       "\\`[A-Z]+[0-9]+\\'" regexp .
+       (ses-create-cell-variable): New defun.
+       (ses-relocate-formula): Relocate formulas only for cells the
+       symbols of which are not renamed, i.e. symbols whose names do not
+       match regexp "\\`[A-Z]+[0-9]+\\'".
+       (ses-relocate-all): Relocate values only for cells the symbols of
+       which are not renamed.
+       (ses-load): Create cells variables as the (ses-cell ...) are read,
+       in order to check row col consistency with cell symbol name only
+       for cells that are not renamed.
+       (ses-replace-name-in-formula): New defun.
+       (ses-rename-cell): New defun.
+       (ses-call-printer-return, ses-cell-property-get)
+       (ses-sym-rowcol, ses-printer-validate, ses-formula-record)
+       (ses-create-cell-variable, ses-reset-header-string)
+       (ses-cell-set-formula, ses-repair-cell-reference-all)
+       (ses-self-reference-early-detection, ses-in-print-area, ses-set-curcell)
+       (ses-check-curcell, ses-call-printer, ses-adjust-print-width)
+       (ses-print-cell-new-width, ses-formula-references, ses-relocate-formula)
+       (ses-aset-with-undo, ses-load, ses-truncate-cell)
+       (ses-read-column-printer, ses-read-default-printer, ses-insert-row)
+       (ses-delete-row, ses-delete-column, ses-append-row-jump-first-column)
+       (ses-kill-override, ses-yank-pop, ses-yank-cells, ses-yank-tsf)
+       (ses-yank-resize, ses-export-tab, ses-mark-row, ses-mark-column)
+       (ses-renarrow-buffer, ses-insert-range, ses-insert-ses-range)
+       (ses-safe-printer, ses-safe-formula, ses-warn-unsafe, ses--clean-!)
+       (ses--clean-_, ses-range, ses-select, ses-center, ses-center-span)
+       (ses-dashfill, ses-unsafe): Fix typos and reflow docstrings.
+
+
 2012-03-23  Stefan Monnier  <monnier@iro.umontreal.ca>
 
        * newcomment.el (comment-choose-indent): No space after BOL.
index 2a12f03..5382e60 100644 (file)
@@ -1602,6 +1602,38 @@ to which that point should be aligned, if we were to reindent it.")
           (save-excursion (indent-line-to indent))
         (indent-line-to indent)))))
 
+(defun smie-auto-fill ()
+  (let ((fc (current-fill-column))
+        (try-again nil))
+    (while (and fc (> (current-column) fc))
+      (cond
+       ((not (or (nth 8 (save-excursion
+                          (syntax-ppss (line-beginning-position))))
+                 (nth 8 (syntax-ppss))))
+        (save-excursion
+          (beginning-of-line)
+          (smie-indent-forward-token)
+          (let ((bsf (point))
+                (gain 0)
+                curcol)
+            (while (<= (setq curcol (current-column)) fc)
+              ;; FIXME?  `smie-indent-calculate' can (and often will)
+              ;; return a result that actually depends on the presence/absence
+              ;; of a newline, so the gain computed here may not be accurate,
+              ;; but in practice it seems to works well enough.
+              (let* ((newcol (smie-indent-calculate))
+                     (newgain (- curcol newcol)))
+                (when (> newgain gain)
+                  (setq gain newgain)
+                  (setq bsf (point))))
+              (smie-indent-forward-token))
+            (when (> gain 0)
+              (setq try-again)
+              (goto-char bsf)
+              (newline-and-indent)))))
+       (t (do-auto-fill))))))
+
+
 (defun smie-setup (grammar rules-function &rest keywords)
   "Setup SMIE navigation and indentation.
 GRAMMAR is a grammar table generated by `smie-prec2->grammar'.
@@ -1612,6 +1644,7 @@ KEYWORDS are additional arguments, which can use the following keywords:
   (set (make-local-variable 'smie-rules-function) rules-function)
   (set (make-local-variable 'smie-grammar) grammar)
   (set (make-local-variable 'indent-line-function) 'smie-indent-line)
+  (set (make-local-variable 'normal-auto-fill-function) 'smie-auto-fill)
   (set (make-local-variable 'forward-sexp-function)
        'smie-forward-sexp-command)
   (while keywords
index 40bb36d..ce6ba43 100644 (file)
@@ -269,6 +269,18 @@ makes the comment easier to read.  Default is 1.  nil means 0."
   :type '(choice string integer (const nil))
   :group 'comment)
 
+(defcustom comment-inline-offset 1
+  "Inline comments have to be preceded by at least this many spaces.
+This is usefull when style-conventions require a certain minimal offset.
+Python's PEP8 for example recommends two spaces, so you could do:
+
+\(add-hook 'python-mode-hook
+   (lambda nil (set (make-local-variable 'comment-inline-offset) 2)))
+
+See `comment-padding' for whole-line comments."
+  :type 'integer
+  :group 'comment)
+
 ;;;###autoload
 (defcustom comment-multi-line nil
   "Non-nil means `comment-indent-new-line' continues comments.
@@ -586,8 +598,9 @@ Point is expected to be at the start of the comment."
                 (- (or comment-fill-column fill-column)
                    (save-excursion (end-of-line) (current-column)))))
         (other nil)
-        (min (save-excursion (skip-chars-backward " \t")
-                             (if (bolp) 0 (1+ (current-column))))))
+        (min (save-excursion
+               (skip-chars-backward " \t")
+               (if (bolp) 0 (+ comment-inline-offset (current-column))))))
     ;; Fix up the range.
     (if (< max min) (setq max min))
     ;; Don't move past the fill column.
@@ -687,7 +700,8 @@ If CONTINUE is non-nil, use the `comment-continue' markers if any."
          (save-excursion
            (skip-chars-backward " \t")
            (unless (bolp)
-             (setq indent (max indent (1+ (current-column))))))
+             (setq indent (max indent
+                                (+ (current-column) comment-inline-offset)))))
          ;; If that's different from comment's current position, change it.
          (unless (= (current-column) indent)
            (delete-region (point) (progn (skip-chars-backward " \t") (point)))
index 0638fc3..da18046 100644 (file)
@@ -282,6 +282,9 @@ default printer and then modify its output.")
       ses--numcols ses--numrows ses--symbolic-formulas
       ses--data-marker ses--params-marker (ses--Dijkstra-attempt-nb . 0)
       ses--Dijkstra-weight-bound
+      ;; This list is useful to speed-up clean-up of symbols when
+      ;; an area containing renamed cell is deleted.
+      ses--renamed-cell-symb-list
       ;; Global variables that we override
       mode-line-process next-line-add-newlines transient-mark-mode)
     "Buffer-local variables used by SES.")
@@ -674,6 +677,17 @@ for this spreadsheet."
        (put sym 'ses-cell (cons xrow xcol))
        (make-local-variable sym)))))
 
+(defun ses-create-cell-variable (sym row col)
+  "Create a buffer-local variable `SYM' for cell at position (ROW, COL).
+
+SYM is the symbol for that variable, ROW and COL are integers for
+row and column of the cell, with numbering starting from 0.
+
+Return nil in case of failure."
+  (unless (local-variable-p sym)
+    (make-local-variable  sym)
+    (put sym 'ses-cell (cons row col))))
+
 ;; We do not delete the ses-cell properties for the cell-variables, in
 ;; case a formula that refers to this cell is in the kill-ring and is
 ;; later pasted back in.
@@ -682,7 +696,10 @@ for this spreadsheet."
   (let (sym)
     (dotimes (row (1+ (- maxrow minrow)))
       (dotimes (col (1+ (- maxcol mincol)))
-       (setq sym (ses-create-cell-symbol (+ row minrow) (+ col mincol)))
+       (let ((xrow  (+ row minrow)) (xcol (+ col mincol)))
+         (setq sym (if (and (< xrow ses--numrows) (< xcol ses--numcols))
+                       (ses-cell-symbol xrow xcol)
+                       (ses-create-cell-symbol xrow xcol))))
        (if (boundp sym)
            (push `(apply ses-set-with-undo ,sym ,(symbol-value sym))
                  buffer-undo-list))
@@ -1400,7 +1417,8 @@ removed.  Example:
 Sets `ses-relocate-return' to 'delete if cell-references were removed."
   (let (rowcol result)
     (if (or (atom formula) (eq (car formula) 'quote))
-       (if (setq rowcol (ses-sym-rowcol formula))
+       (if (and (setq rowcol (ses-sym-rowcol formula))
+                (string-match "\\`[A-Z]+[0-9]+\\'" (symbol-name formula)))
            (ses-relocate-symbol formula rowcol
                                 startrow startcol rowincr colincr)
          formula) ; Pass through as-is.
@@ -1508,14 +1526,15 @@ if the range was altered."
 the rectangle (MINROW,MINCOL)..(NUMROWS,NUMCOLS) by adding ROWINCR and COLINCR
 to each symbol."
   (let (reform)
-    (let (mycell newval)
+    (let (mycell newval xrow)
       (dotimes-with-progress-reporter
          (row ses--numrows) "Relocating formulas..."
        (dotimes (col ses--numcols)
          (setq ses-relocate-return nil
                mycell (ses-get-cell row col)
                newval (ses-relocate-formula (ses-cell-formula mycell)
-                                            minrow mincol rowincr colincr))
+                                            minrow mincol rowincr colincr)
+               xrow  (- row rowincr))
          (ses-set-cell row col 'formula newval)
          (if (eq ses-relocate-return 'range)
              ;; This cell contains a (ses-range X Y) where a cell has been
@@ -1531,8 +1550,22 @@ to each symbol."
                                             minrow mincol rowincr colincr))
          (ses-set-cell row col 'references newval)
          (and (>= row minrow) (>= col mincol)
-              (ses-set-cell row col 'symbol
-                            (ses-create-cell-symbol row col))))))
+              (let ((sym (ses-cell-symbol row col))
+                    (xcol (- col colincr)))
+                (if (and
+                     sym
+                     (>= xrow 0)
+                     (>= xcol 0)
+                     (null (eq sym
+                               (ses-create-cell-symbol xrow xcol))))
+                    ;; This is a renamed cell, do not update the cell
+                    ;; name, but just update the coordinate property.
+                    (put sym 'ses-cell (cons row col))
+                  (ses-set-cell row col 'symbol
+                                (setq sym (ses-create-cell-symbol row col)))
+                  (unless (and (boundp sym) (local-variable-p sym))
+                    (set (make-local-variable sym) nil)
+                    (put sym 'ses-cell (cons row col)))))) )))
     ;; Relocate the cell values.
     (let (oldval myrow mycol xrow xcol)
       (cond
@@ -1545,11 +1578,17 @@ to each symbol."
            (setq mycol  (+ col mincol)
                  xrow   (- myrow rowincr)
                  xcol   (- mycol colincr))
-           (if (and (< xrow ses--numrows) (< xcol ses--numcols))
-               (setq oldval (ses-cell-value xrow xcol))
-             ;; Cell is off the end of the array.
-             (setq oldval (symbol-value (ses-create-cell-symbol xrow xcol))))
-           (ses-set-cell myrow mycol 'value oldval))))
+           (let ((sym (ses-cell-symbol myrow mycol))
+                 (xsym (ses-create-cell-symbol xrow xcol)))
+             ;; Make the value relocation only when if the cell is not
+             ;; a renamed cell.  Otherwise this is not needed.
+             (and (eq sym xsym)
+                 (ses-set-cell myrow mycol 'value
+                   (if (and (< xrow ses--numrows) (< xcol ses--numcols))
+                       (ses-cell-value xrow xcol)
+                     ;;Cell is off the end of the array
+                     (symbol-value xsym))))))))
+
        ((and (wholenump rowincr) (wholenump colincr))
        ;; Insertion of rows and/or columns.  Run the loop backwards.
        (let ((disty (1- ses--numrows))
@@ -1659,7 +1698,6 @@ Does not execute cell formulas or print functions."
        (message "Upgrading from SES-1 file format")))
     (or (= ses--file-format 2)
        (error "This file needs a newer version of the SES library code"))
-    (ses-create-cell-variable-range 0 (1- ses--numrows) 0 (1- ses--numcols))
     ;; Initialize cell array.
     (setq ses--cells (make-vector ses--numrows nil))
     (dotimes (row ses--numrows)
@@ -1679,11 +1717,10 @@ Does not execute cell formulas or print functions."
   (dotimes (row ses--numrows)
     (dotimes (col ses--numcols)
       (let* ((x      (read (current-buffer)))
-            (rowcol (ses-sym-rowcol (car-safe (cdr-safe x)))))
+            (sym  (car-safe (cdr-safe x))))
        (or (and (looking-at "\n")
                 (eq (car-safe x) 'ses-cell)
-                (eq row (car rowcol))
-                (eq col (cdr rowcol)))
+                (ses-create-cell-variable sym row col))
            (error "Cell-def error"))
        (eval x)))
     (or (looking-at "\n\n")
@@ -3140,6 +3177,63 @@ highlighted range in the spreadsheet."
   (mouse-set-point event)
   (ses-insert-ses-range))
 
+(defun ses-replace-name-in-formula (formula old-name new-name)
+  (let ((new-formula formula))
+    (unless (and (consp formula)
+                (eq (car-safe formula) 'quote))
+      (while formula
+       (let ((elt (car-safe formula)))
+         (cond
+          ((consp elt)
+           (setcar formula (ses-replace-name-in-formula elt old-name new-name)))
+          ((and (symbolp elt)
+                (eq (car-safe formula) old-name))
+           (setcar formula new-name))))
+       (setq formula (cdr formula))))
+    new-formula))
+
+(defun ses-rename-cell (new-name)
+  "Rename current cell."
+  (interactive "*SEnter new name: ")
+  (ses-check-curcell)
+  (or
+   (and  (local-variable-p new-name)
+        (ses-sym-rowcol new-name)
+        ;; this test is needed because ses-cell property of deleted cells
+        ;; is not deleted in case of subsequent undo
+        (memq new-name ses--renamed-cell-symb-list)
+        (error "Already a cell name"))
+   (and (boundp new-name)
+       (null (yes-or-no-p (format "`%S' is already bound outside this buffer, continue? "
+                                  new-name)))
+       (error "Already a bound cell name")))
+  (let* ((rowcol (ses-sym-rowcol ses--curcell))
+        (cell (ses-get-cell (car rowcol) (cdr rowcol))))
+    (put new-name 'ses-cell rowcol)
+    (dolist (reference (ses-cell-references (car rowcol) (cdr rowcol)))
+      (let* ((rowcol (ses-sym-rowcol reference))
+            (cell  (ses-get-cell (car rowcol) (cdr rowcol))))
+       (ses-cell-set-formula (car rowcol)
+                             (cdr rowcol)
+                             (ses-replace-name-in-formula
+                              (ses-cell-formula cell)
+                              ses--curcell
+                              new-name))))
+    (push new-name ses--renamed-cell-symb-list)
+    (set new-name (symbol-value ses--curcell))
+    (aset cell 0 new-name)
+    (put ses--curcell 'ses-cell nil)
+    (makunbound ses--curcell)
+    (setq ses--curcell new-name)
+    (let* ((pos (point))
+          (inhibit-read-only t)
+          (col (current-column))
+          (end (save-excursion
+                 (move-to-column (1+ col))
+                 (if (eolp)
+                     (+ pos (ses-col-width col) 1)
+                   (point)))))
+      (put-text-property pos end 'intangible new-name))) )
 
 ;;----------------------------------------------------------------------------
 ;; Checking formulas for safety