mirror of
https://github.com/vale981/emacs-ipython-notebook
synced 2025-03-05 09:01:40 -05:00
syntax-propertize-chunks takes us too far afield
This commit is contained in:
parent
204e944d8d
commit
b478940c9f
4 changed files with 21 additions and 130 deletions
|
@ -2047,16 +2047,6 @@ Used for `flyspell-generic-check-word-predicate'."
|
||||||
ein:markdown-inline-code-face
|
ein:markdown-inline-code-face
|
||||||
ein:markdown-url-face))))))))
|
ein:markdown-url-face))))))))
|
||||||
|
|
||||||
(defun ein:markdown-font-lock-ensure ()
|
|
||||||
"Provide `font-lock-ensure' in Emacs 24."
|
|
||||||
(if (fboundp 'font-lock-ensure)
|
|
||||||
(font-lock-ensure)
|
|
||||||
(with-no-warnings
|
|
||||||
;; Suppress warning about non-interactive use of
|
|
||||||
;; `font-lock-fontify-buffer' in Emacs 25.
|
|
||||||
(font-lock-fontify-buffer))))
|
|
||||||
|
|
||||||
|
|
||||||
;;; ein:markdown Parsing Functions ================================================
|
;;; ein:markdown Parsing Functions ================================================
|
||||||
|
|
||||||
(define-obsolete-function-alias
|
(define-obsolete-function-alias
|
||||||
|
@ -6961,24 +6951,6 @@ Translate filenames using `markdown-filename-translate-function'."
|
||||||
(add-text-properties start end props)
|
(add-text-properties start end props)
|
||||||
t)))
|
t)))
|
||||||
|
|
||||||
(defun ein:markdown-extend-changed-region (from to)
|
|
||||||
"Extend region given by FROM and TO so that we can fontify all links.
|
|
||||||
The region is extended to the first newline before and the first
|
|
||||||
newline after."
|
|
||||||
;; start looking for the first new line before 'from
|
|
||||||
(goto-char from)
|
|
||||||
(re-search-backward "\n" nil t)
|
|
||||||
(let ((new-from (point-min))
|
|
||||||
(new-to (point-max)))
|
|
||||||
(if (not (= (point) from))
|
|
||||||
(setq new-from (point)))
|
|
||||||
;; do the same thing for the first new line after 'to
|
|
||||||
(goto-char to)
|
|
||||||
(re-search-forward "\n" nil t)
|
|
||||||
(if (not (= (point) to))
|
|
||||||
(setq new-to (point)))
|
|
||||||
(cl-values new-from new-to)))
|
|
||||||
|
|
||||||
;;; Following & Doing =========================================================
|
;;; Following & Doing =========================================================
|
||||||
|
|
||||||
(defun ein:markdown-follow-thing-at-point (_arg)
|
(defun ein:markdown-follow-thing-at-point (_arg)
|
||||||
|
@ -7272,40 +7244,6 @@ Use matching function MATCHER."
|
||||||
"Add text properties to next tilde fenced code block from point to LAST."
|
"Add text properties to next tilde fenced code block from point to LAST."
|
||||||
(ein:markdown-fontify-code-blocks-generic 'ein:markdown-match-fenced-code-blocks last))
|
(ein:markdown-fontify-code-blocks-generic 'ein:markdown-match-fenced-code-blocks last))
|
||||||
|
|
||||||
|
|
||||||
(require 'edit-indirect nil t)
|
|
||||||
(defvar edit-indirect-guess-mode-function)
|
|
||||||
(defvar edit-indirect-after-commit-functions)
|
|
||||||
|
|
||||||
(defun ein:markdown--edit-indirect-after-commit-function (_beg end)
|
|
||||||
"Ensure trailing newlines at the END of code blocks."
|
|
||||||
(goto-char end)
|
|
||||||
(unless (eq (char-before) ?\n)
|
|
||||||
(insert "\n")))
|
|
||||||
|
|
||||||
(defun ein:markdown-edit-code-block ()
|
|
||||||
"Edit ein:markdown code block in an indirect buffer."
|
|
||||||
(interactive)
|
|
||||||
(save-excursion
|
|
||||||
(if (fboundp 'edit-indirect-region)
|
|
||||||
(let* ((bounds (ein:markdown-get-enclosing-fenced-block-construct))
|
|
||||||
(begin (and bounds (goto-char (nth 0 bounds)) (point-at-bol 2)))
|
|
||||||
(end (and bounds (goto-char (nth 1 bounds)) (point-at-bol 1))))
|
|
||||||
(if (and begin end)
|
|
||||||
(let* ((lang (ein:markdown-code-block-lang))
|
|
||||||
(mode (or (and lang (ein:markdown-get-lang-mode lang))
|
|
||||||
ein:markdown-edit-code-block-default-mode))
|
|
||||||
(edit-indirect-guess-mode-function
|
|
||||||
(lambda (_parent-buffer _beg _end)
|
|
||||||
(funcall mode))))
|
|
||||||
(edit-indirect-region begin end 'display-buffer))
|
|
||||||
(user-error "Not inside a GFM or tilde fenced code block")))
|
|
||||||
(when (y-or-n-p "Package edit-indirect needed to edit code blocks. Install it now? ")
|
|
||||||
(progn (package-refresh-contents)
|
|
||||||
(package-install 'edit-indirect)
|
|
||||||
(ein:markdown-edit-code-block))))))
|
|
||||||
|
|
||||||
|
|
||||||
;;; Table Editing =============================================================
|
;;; Table Editing =============================================================
|
||||||
|
|
||||||
;; These functions were originally adapted from `org-table.el'.
|
;; These functions were originally adapted from `org-table.el'.
|
||||||
|
@ -8134,12 +8072,7 @@ rows and columns and the column alignment."
|
||||||
;; Backwards compatibility with ein:markdown-css-path
|
;; Backwards compatibility with ein:markdown-css-path
|
||||||
(when (boundp 'ein:markdown-css-path)
|
(when (boundp 'ein:markdown-css-path)
|
||||||
(warn "ein:markdown-css-path is deprecated, see ein:markdown-css-paths.")
|
(warn "ein:markdown-css-path is deprecated, see ein:markdown-css-paths.")
|
||||||
(add-to-list 'ein:markdown-css-paths ein:markdown-css-path))
|
(add-to-list 'ein:markdown-css-paths ein:markdown-css-path)))
|
||||||
|
|
||||||
;; edit-indirect
|
|
||||||
(add-hook 'edit-indirect-after-commit-functions
|
|
||||||
#'ein:markdown--edit-indirect-after-commit-function
|
|
||||||
nil 'local))
|
|
||||||
|
|
||||||
(ein:markdown-update-header-faces)
|
(ein:markdown-update-header-faces)
|
||||||
(provide 'ein-markdown-mode)
|
(provide 'ein-markdown-mode)
|
||||||
|
|
|
@ -45,7 +45,6 @@
|
||||||
(require 'ein-kernelinfo)
|
(require 'ein-kernelinfo)
|
||||||
(require 'ein-cell)
|
(require 'ein-cell)
|
||||||
(require 'ein-worksheet)
|
(require 'ein-worksheet)
|
||||||
(require 'ein-iexec)
|
|
||||||
(require 'ein-scratchsheet)
|
(require 'ein-scratchsheet)
|
||||||
(require 'ein-notification)
|
(require 'ein-notification)
|
||||||
(require 'ein-completer)
|
(require 'ein-completer)
|
||||||
|
|
|
@ -64,26 +64,27 @@
|
||||||
(fmakunbound 'poly-lock-mode)
|
(fmakunbound 'poly-lock-mode)
|
||||||
(defalias 'poly-lock-mode (symbol-function (default-value 'font-lock-function)))
|
(defalias 'poly-lock-mode (symbol-function (default-value 'font-lock-function)))
|
||||||
|
|
||||||
|
(defun poly-ein--syntax-propertize (pos)
|
||||||
|
(prog1 poly-ein-mode
|
||||||
|
(when (and poly-ein-mode (< syntax-propertize--done pos))
|
||||||
|
(save-excursion
|
||||||
|
;; pared down from default `syntax-propertize'
|
||||||
|
(with-silent-modifications
|
||||||
|
(let ((parse-sexp-lookup-properties t)
|
||||||
|
(start (point-min)) ;; i've narrowed in the :around
|
||||||
|
(end (point-max))
|
||||||
|
(span (pm-innermost-span pos)))
|
||||||
|
(setq syntax-propertize--done end)
|
||||||
|
(when (eq 'body (nth 0 span))
|
||||||
|
(remove-text-properties start end
|
||||||
|
'(syntax-table nil syntax-multiline nil))
|
||||||
|
;; avoid recursion if syntax-propertize-function calls me (syntax-propertize)
|
||||||
|
(when syntax-propertize-function
|
||||||
|
(let ((syntax-propertize--done most-positive-fixnum))
|
||||||
|
(funcall syntax-propertize-function start end))))))))))
|
||||||
(add-function
|
(add-function
|
||||||
:before-until (symbol-function 'syntax-propertize)
|
:before-until (symbol-function 'syntax-propertize)
|
||||||
(lambda (pos)
|
#'poly-ein--syntax-propertize)
|
||||||
(prog1 poly-ein-mode
|
|
||||||
(when (and poly-ein-mode (< syntax-propertize--done pos))
|
|
||||||
(save-excursion
|
|
||||||
;; pared down from default `syntax-propertize'
|
|
||||||
(with-silent-modifications
|
|
||||||
(let ((parse-sexp-lookup-properties t)
|
|
||||||
(start (point-min)) ;; i've narrowed in the :around
|
|
||||||
(end (point-max))
|
|
||||||
(span (pm-innermost-span pos)))
|
|
||||||
(setq syntax-propertize--done end)
|
|
||||||
(when (eq 'body (nth 0 span))
|
|
||||||
(remove-text-properties start end
|
|
||||||
'(syntax-table nil syntax-multiline nil))
|
|
||||||
;; avoid recursion if syntax-propertize-function calls me (syntax-propertize)
|
|
||||||
(when syntax-propertize-function
|
|
||||||
(let ((syntax-propertize--done most-positive-fixnum))
|
|
||||||
(funcall syntax-propertize-function start end)))))))))))
|
|
||||||
|
|
||||||
(add-function
|
(add-function
|
||||||
:around (symbol-function 'syntax-propertize)
|
:around (symbol-function 'syntax-propertize)
|
||||||
|
@ -263,6 +264,7 @@ TYPE can be 'body, nil."
|
||||||
(buffer-local-value 'after-change-functions (pm-base-buffer)))
|
(buffer-local-value 'after-change-functions (pm-base-buffer)))
|
||||||
(poly-ein-copy-state (pm-base-buffer) (current-buffer))
|
(poly-ein-copy-state (pm-base-buffer) (current-buffer))
|
||||||
(setq-local font-lock-dont-widen t)
|
(setq-local font-lock-dont-widen t)
|
||||||
|
(setq-local syntax-propertize-chunks 0) ;; internal--syntax-propertize too far
|
||||||
(ein:notebook-mode))
|
(ein:notebook-mode))
|
||||||
|
|
||||||
(defcustom pm-host/ein
|
(defcustom pm-host/ein
|
||||||
|
|
|
@ -1,43 +0,0 @@
|
||||||
(eval-when-compile (require 'cl))
|
|
||||||
(require 'ert)
|
|
||||||
|
|
||||||
(require 'ein-iexec)
|
|
||||||
(require 'ein-testing-notebook)
|
|
||||||
|
|
||||||
|
|
||||||
;;; `ein:iexec-should-execute-p'
|
|
||||||
|
|
||||||
(defun* eintest:iexec-should-execute-p (cell &key (this-command t) beg end)
|
|
||||||
"Simple wrapper for `ein:iexec-should-execute-p' which
|
|
||||||
returns `t' by default, if the CELL is code cell."
|
|
||||||
(unless beg (setq beg (ein:cell-input-pos-min cell)))
|
|
||||||
(unless end (setq end (ein:cell-input-pos-max cell)))
|
|
||||||
(ein:iexec-should-execute-p cell beg end))
|
|
||||||
|
|
||||||
;; cell types
|
|
||||||
|
|
||||||
(ert-deftest ein:iexec-should-execute-p-codecell ()
|
|
||||||
(ein:testing-with-one-cell 'code
|
|
||||||
(should (eintest:iexec-should-execute-p cell))))
|
|
||||||
|
|
||||||
(ert-deftest ein:iexec-should-execute-p-markdowncell ()
|
|
||||||
(ein:testing-with-one-cell 'markdown
|
|
||||||
(should-not (eintest:iexec-should-execute-p cell))))
|
|
||||||
|
|
||||||
(ert-deftest ein:iexec-should-execute-p-dead-cell ()
|
|
||||||
(ein:testing-with-one-cell 'code
|
|
||||||
(should-not (eintest:iexec-should-execute-p (ein:cell-copy cell)))))
|
|
||||||
|
|
||||||
;; other
|
|
||||||
|
|
||||||
(ert-deftest ein:iexec-should-execute-p-non-interactive ()
|
|
||||||
(ein:testing-with-one-cell 'code
|
|
||||||
(should-not (eintest:iexec-should-execute-p cell :this-command nil))))
|
|
||||||
|
|
||||||
(ert-deftest ein:iexec-should-execute-p-beg-too-small ()
|
|
||||||
(ein:testing-with-one-cell 'code
|
|
||||||
(should-not (eintest:iexec-should-execute-p cell :beg (point-min)))))
|
|
||||||
|
|
||||||
(ert-deftest ein:iexec-should-execute-p-end-too-big ()
|
|
||||||
(ein:testing-with-one-cell 'code
|
|
||||||
(should-not (eintest:iexec-should-execute-p cell :end (point-max)))))
|
|
Loading…
Add table
Reference in a new issue