Changeset e6de219 in git for emacs/singular.el
- Timestamp:
- Jul 28, 1998, 4:44:57 PM (26 years ago)
- Branches:
- (u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
- Children:
- 73a5d17024f576058268b69583f17de25e4a6244
- Parents:
- 16352da6e80e3ad4aba6464692035a8e077dd04f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
emacs/singular.el
r16352d re6de219 1 1 ;;; singular.el --- Emacs support for Computer Algebra System Singular 2 2 3 ;; $Id: singular.el,v 1. 7 1998-07-28 10:45:56schmidt Exp $3 ;; $Id: singular.el,v 1.8 1998-07-28 14:44:57 schmidt Exp $ 4 4 5 5 ;;; Commentary: … … 59 59 (defun singular-debug-format (string) 60 60 "Return STRING in a nicer format." 61 (while (string-match "\n" string) 62 (setq string (replace-match "^J" nil nil string))) 63 64 (if (> (length string) 16) 65 (concat "<" (substring string 0 7) ">...<" (substring string -8) ">") 66 (concat "<" string ">"))) 61 (save-match-data 62 (while (string-match "\n" string) 63 (setq string (replace-match "^J" nil nil string))) 64 65 (if (> (length string) 16) 66 (concat "<" (substring string 0 7) ">...<" (substring string -8) ">") 67 (concat "<" string ">")))) 67 68 68 69 (defmacro singular-debug (mode form &optional else-form) … … 150 151 (defun singular-lookup-face (face-type) 151 152 "Return face belonging to FACE-TYPE. 152 NOT READY [should be rewritten completely ]!"153 NOT READY [should be rewritten completely. Interface should stay the same.]!" 153 154 (cond ((eq face-type 'input) singular-input-face) 154 155 ((eq face-type 'output) singular-output-face))) … … 161 162 "Key map to use in Singular interactive mode.") 162 163 163 (if (not singular-interactive-mode-map)164 ( progn165 166 167 168 169 170 171 172 173 174 175 176 (define-key singular-interactive-mode-map "\C-m" 'singular-send-input)))164 (if singular-interactive-mode-map 165 () 166 (cond 167 ;; Emacs 168 ((eq singular-emacs-flavor 'emacs) 169 (setq singular-interactive-mode-map 170 (nconc (make-sparse-keymap) comint-mode-map))) 171 ;; XEmacs 172 (t 173 (setq singular-interactive-mode-map (make-keymap)) 174 (set-keymap-parents singular-interactive-mode-map (list comint-mode-map)) 175 (set-keymap-name singular-interactive-mode-map 176 'singular-interactive-mode-map))) 177 (define-key singular-interactive-mode-map "\C-m" 'singular-send-input)) 177 178 ;;}}} 178 179 … … 268 269 269 270 (defvar singular-simple-sec-clear-type 'input 270 "Type of clear simple sections.") 271 "Type of clear simple sections. 272 If nil no clear simple sections are used.") 273 274 (defvar singular-simple-sec-last-end nil 275 "Marker at the end of the last simple section.") 271 276 272 277 (defun singular-simple-sec-init (pos) … … 289 294 (singular-fset 'singular-simple-sec-create 290 295 'singular-emacs-simple-sec-create 291 'singular- emacs-simple-sec-create)296 'singular-xemacs-simple-sec-create) 292 297 293 298 (singular-fset 'singular-simple-sec-reset-last 294 299 'singular-emacs-simple-sec-reset-last 295 'singular- emacs-simple-sec-reset-last)300 'singular-xemacs-simple-sec-reset-last) 296 301 297 302 (singular-fset 'singular-simple-sec-start 298 303 'singular-emacs-simple-sec-start 299 'singular- emacs-simple-sec-start)304 'singular-xemacs-simple-sec-start) 300 305 301 306 (singular-fset 'singular-simple-sec-end 302 307 'singular-emacs-simple-sec-end 303 'singular-emacs-simple-sec-end) 308 'singular-xemacs-simple-sec-end) 309 310 (singular-fset 'singular-simple-sec-start-at 311 'singular-emacs-simple-sec-start-at 312 'singular-xemacs-simple-sec-start-at) 313 314 (singular-fset 'singular-simple-sec-end-at 315 'singular-emacs-simple-sec-end-at 316 'singular-xemacs-simple-sec-end-at) 304 317 305 318 (singular-fset 'singular-simple-sec-type 306 319 'singular-emacs-simple-sec-type 307 'singular- emacs-simple-sec-type)320 'singular-xemacs-simple-sec-type) 308 321 309 322 (singular-fset 'singular-simple-sec-at 310 323 'singular-emacs-simple-sec-at 311 'singular- emacs-simple-sec-at)324 'singular-xemacs-simple-sec-at) 312 325 313 326 (singular-fset 'singular-simple-sec-before 314 327 'singular-emacs-simple-sec-before 315 'singular- emacs-simple-sec-before)328 'singular-xemacs-simple-sec-before) 316 329 317 330 (singular-fset 'singular-simple-sec-in 318 331 'singular-emacs-simple-sec-in 319 'singular- emacs-simple-sec-in)332 'singular-xemacs-simple-sec-in) 320 333 ;;}}} 321 334 … … 326 339 Returns the new simple section or `empty' if no simple section has 327 340 been created. 341 Assumes that no narrowing is in effect. 328 342 Updates `singular-simple-sec-last-end'." 329 343 (let ((last-end (marker-position singular-simple-sec-last-end)) … … 331 345 simple-sec) 332 346 333 ;; get beginning of line before END 334 (setq end (let ((save-point (point))) 347 ;; get beginning of line before END. At this point we need that there 348 ;; are no restrictions. 349 (setq end (let ((old-point (point))) 335 350 (goto-char end) (beginning-of-line) 336 (prog1 (point) (goto-char save-point))))351 (prog1 (point) (goto-char old-point)))) 337 352 338 353 (cond … … 360 375 simple-sec)) 361 376 362 (defun singular-emacs-simple-sec-reset-last ( )363 "Reset end of last simple section after accidental extension."364 (let ((simple-sec (singular-emacs-simple-sec-at singular-simple-sec-last-end))) 365 (if simple-sec366 (move-overlay simple-sec (overlay-start simple-sec)367 singular-simple-sec-last-end))))377 (defun singular-emacs-simple-sec-reset-last (pos) 378 "Reset end of last simple section to POS after accidental extension. 379 Updates `singular-simple-sec-last-end', too." 380 (let ((simple-sec (singular-emacs-simple-sec-at pos))) 381 (if simple-sec (move-overlay simple-sec (overlay-start simple-sec) pos)) 382 (set-marker singular-simple-sec-last-end pos))) 368 383 369 384 (defun singular-emacs-simple-sec-start (simple-sec) … … 374 389 "Return end of non-clear simple section SIMPLE-SEC." 375 390 (overlay-end simple-sec)) 391 392 (defun singular-emacs-simple-sec-start-at (pos) 393 "Return start of clear section at position POS." 394 (save-restriction 395 (widen) 396 (let ((previous-overlay-change (1+ (point)))) 397 ;; this `while' loop at last will run into the end of the next 398 ;; non-clear overlay or stop at bob. Since POS may be right at the end 399 ;; of a previous non-clear location, we have to search at least one 400 ;; time from POS+1 backwards. 401 (while (not 402 (or (singular-emacs-simple-sec-before previous-overlay-change) 403 (eq previous-overlay-change (point-min)))) 404 (setq previous-overlay-change 405 (previous-overlay-change previous-overlay-change))) 406 previous-overlay-change))) 407 408 (defun singular-emacs-simple-sec-end-at (pos) 409 "Return end of clear section at position POS." 410 (save-restriction 411 (widen) 412 (let ((next-overlay-change (next-overlay-change (point)))) 413 ;; this `while' loop at last will run into the beginning of the next 414 ;; non-clear overlay or stop at eob. Since POS may not be at the 415 ;; beginning of a non-clear simple section we may start searching 416 ;; immediately. 417 (while (not 418 (or (singular-emacs-simple-sec-at next-overlay-change) 419 (eq next-overlay-change (point-max)))) 420 (setq next-overlay-change 421 (next-overlay-change next-overlay-change))) 422 next-overlay-change))) 376 423 377 424 (defun singular-emacs-simple-sec-type (simple-sec) … … 415 462 ;; sections?]! 416 463 417 (defun singular-section-at (pos &optional r aw-section)464 (defun singular-section-at (pos &optional restricted) 418 465 "Return section at position POS. 419 Returns section intersected with current restriction unless420 RAW-SECTION isnon-nil."466 Returns section intersected with current restriction if RESTRICTED is 467 non-nil." 421 468 (let* ((simple-sec (singular-simple-sec-at pos)) 422 469 (type (singular-simple-sec-type simple-sec)) … … 427 474 (singular-simple-sec-end simple-sec) 428 475 (singular-simple-sec-end-at pos)))) 429 (if r aw-section430 (vector simple-sec type start end)431 (vector simple-sec type 432 (max start (point-min)) (min end (point-max))))))476 (if restricted 477 (vector simple-sec type 478 (max start (point-min)) (min end (point-max))) 479 (vector simple-sec type start end)))) 433 480 434 481 (defmacro singular-section-simple-sec (section) … … 453 500 "Ellipsis to show for folded input or output.") 454 501 455 (defun singular-fold-internal (start end fold) 456 "(Un)fold region from START to END. 502 (defun singular-fold-internal (list fold) 503 "(Un)fold regions in LIST. 504 LIST should have the format (START1 END1 START2 END2 ...). 457 505 Folds if FOLD is non-nil, otherwise unfolds. 458 506 Folds without affecting undo information, buffer-modified flag, and 459 even for read-only files." 507 even for read-only files. 508 Assumes that there is no narrowing in effect." 460 509 (let ((inhibit-read-only t) (buffer-undo-list t) 461 ( save-modified (buffer-modified-p))462 ( save-point (point)))510 (modified (buffer-modified-p)) 511 (old-point (point))) 463 512 (unwind-protect 464 513 ;; do it !! 465 514 (if fold 466 (progn 467 (goto-char start) (insert ?\r) 468 (subst-char-in-region start end ?\n ?\r t)) 469 (goto-char start) (delete-char 1) 470 (subst-char-in-region start end ?\r ?\n t)) 515 (while list 516 (goto-char (car list)) (insert ?\r) 517 (subst-char-in-region (car list) (nth 1 list) ?\n ?\r t) 518 (setq list (cdr (cdr list)))) 519 (while list 520 (subst-char-in-region (car list) (nth 1 list) ?\r ?\n t) 521 (goto-char (car list)) (delete-char 1) 522 (setq list (cdr (cdr list))))) 471 523 472 524 ;; we have to restore the point and the modified flag. The read-only 473 525 ;; state and undo information are restored by the outer `let'. 474 526 ;; This code is unwide-protected. 475 (goto-char save-point)476 (or save-modified527 (goto-char old-point) 528 (or modified 477 529 (set-buffer-modified-p nil))))) 478 530 479 531 (defun singular-section-foldedp (section) 480 "Return t iff SECTION is folded." 532 "Return t iff SECTION is folded. 533 Assumes that there is no narrowing in effect." 481 534 (eq (char-after (singular-section-start section)) ?\r)) 482 535 … … 486 539 section if called interactively." 487 540 (interactive (list (singular-section-at (point)))) 488 (let ((start (singular-section-start section))) 489 (singular-fold-internal start 490 (singular-section-end section) 491 (not (singular-section-foldedp section))) 492 (if (interactive-p) (goto-char start)))) 541 (let ((start (singular-section-start section)) 542 ;; we have to save restrictions this way since we change text 543 ;; outside the restriction. Note that we do not use a marker for 544 ;; `old-point-min'. This way, even partial narrowed sections are 545 ;; folded properly if they have been narrowed at bol. Nice but 546 ;; dirty trick. 547 (old-point-min (point-min)) 548 (old-point-max (point-max-marker))) 549 (unwind-protect 550 (progn 551 (widen) 552 (singular-fold-internal (list start 553 (singular-section-end section)) 554 (not (singular-section-foldedp section)))) 555 (narrow-to-region old-point-min old-point-max) 556 (set-marker old-point-max nil)) 557 (if (interactive-p) (goto-char (max start (point-min)))))) 493 558 ;;}}} 494 559 … … 691 756 (set-marker comint-last-input-start save-pmark)) 692 757 (and (= singular-simple-sec-last-end (point)) 693 (set-marker singular-simple-sec-last-end save-pmark) 694 (singular-simple-sec-reset-last)) 758 (singular-simple-sec-reset-last save-pmark)) 695 759 696 760 ;; set new markers and create/extend new simple section
Note: See TracChangeset
for help on using the changeset viewer.