summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn Morris <rgm@gnu.org>2012-04-16 20:06:56 -0700
committerGlenn Morris <rgm@gnu.org>2012-04-16 20:06:56 -0700
commit2311d8e5a62b8b6dd7dde45b4b8059d443e2abac (patch)
tree9e526bc6f88f88c2925e05db797570cbc5ad7ee2
parentfc72b15c777af496e9dcbc240f424135379ba955 (diff)
parent699c782b7668c44d0fa4446331b0590a6d5dac82 (diff)
downloademacs-2311d8e5a62b8b6dd7dde45b4b8059d443e2abac.tar.gz
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 @@
+2012-04-17 Stefan Monnier <monnier@iro.umontreal.ca>
+
+ * emacs-lisp/smie.el: Provide smarter auto-filling.
+ (smie-auto-fill): New function.
+ (smie-setup): Use it.
+
+ * newcomment.el (comment-choose-indent): Obey comment-inline-offset.
+
+2012-04-17 Philipp Haselwarter <philipp.haselwarter@gmx.de> (tiny change)
+
+ * newcomment.el (comment-inline-offset): New custom var (bug#11090).
+ (comment-indent): Use it.
+
+2012-04-17 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-localvars): Add ses--renamed-cell-symb-list.
+ (ses-create-cell-variable): New defun.
+ (ses-destroy-cell-variable-range): Respect ses--numrows, ses--numcols.
+ (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.
+
2012-04-17 Peter Oliver <bzr@mavit.org.uk> (tiny change)
* 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.")
(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
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."
: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 useful 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 () (set (make-local-variable 'comment-inline-offset) 2)))
+
+See `comment-padding' for whole-line comments."
+ :version "24.2"
+ :type 'integer
+ :group 'comment)
+
;;;###autoload
(defcustom comment-multi-line nil
"Non-nil means `comment-indent-new-line' continues comments.
@@ -587,7 +600,7 @@ Point is expected to be at the start of the comment."
(save-excursion (end-of-line) (current-column)))))
(other nil)
(min (save-excursion (skip-chars-backward " \t")
- (if (bolp) 0 (1+ (current-column))))))
+ (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)))
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.")
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