;; A block is defined by a line beginning with `sage-block-delimiter'.
(defcustom sage-block-delimiter "###"
"Any line matching the regular expression `sage-block-delimiter' at the
beginning of the line is considered a start of a block.
+(defcustom sage-block-title-decorate " ---- "
+ "When printing titles of blocks, put this decoration around the
+title for easy recognition"
;; Functionality for Sage source files
;; Border-case: if we're standing on a delimiter, sage-backward-block will go
;; to previous delimiter, but we should send from this delimiter and forwards.
- (sage-backward-block 1)
- (sage-send-region (point) p)
+ (let ((enddelim (point)))
+ (sage-backward-block 1)
+ (setq backdelim (point)))
+ (let ((this-buf (current-buffer)))
+ ;; Copy the region to a temp buffer.
+ ;; Possibly change the first line if it contains a title
+ (insert-buffer-substring this-buf backdelim enddelim)
+ (goto-char (point-min))
+ (when (looking-at sage-block-delimiter)
+ (goto-char (match-end 0))
+ (setq title (buffer-substring (point)
+ (progn (end-of-line) (point))))
+ (when (string-match "^ *\\([^ ].*[^ ]\\) *$" title)
+ (setq title (match-string 1 title)))
+ (unless (equal title "")
+ (insert (concat "\nprint(\"" sage-block-title-decorate title sage-block-title-decorate "\")")))))
+ (sage-send-region (point-min) (point-max)))))
(defun sage-blocks-default-keybindings ()
"Bind default keys for working with sage blocks.