diff options
author | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2015-05-01 21:14:19 +0200 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2015-05-01 21:14:19 +0200 |
commit | f8d1d373fcbcbd6642555de6b2c52c55d1f318c1 (patch) | |
tree | 350f4df3873035c2e8c0bf068056753fbd56f911 | |
parent | 427403d0bb600ec6d83ae15a5470bd5175cf9bde (diff) | |
download | org-mode-f8d1d373fcbcbd6642555de6b2c52c55d1f318c1.tar.gz |
org-src: Make area being edited read-only
* lisp/org-src.el (org-src--make-source-overlay): Add read-only
feature to overlay.
(org-edit-src-save): Adapt to change above.
-rw-r--r-- | lisp/org-src.el | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/lisp/org-src.el b/lisp/org-src.el index 5af0b2d..34c5907 100644 --- a/lisp/org-src.el +++ b/lisp/org-src.el @@ -309,15 +309,14 @@ END." (let ((map (make-sparse-keymap))) (define-key map [mouse-1] 'org-edit-src-continue) map)) - ;; TODO: The below line doesn't work for two reasons: - ;; - It should be 'read-only - ;; - 'read-only apparently doesn't work on overlays (also empirically tested): - ;; <https://lists.gnu.org/archive/html/emacs-devel/2008-01/msg01598.html> - ;; If this feature is to be kept, it should be implemented via text - ;; properties, which will require fiddling around in more places - ;; (such as when the contents are copied back into the buffer after - ;; editing is complete.) - (overlay-put overlay :read-only "Leave me alone") + (let ((read-only + (list + (lambda (&rest _) + (user-error + "Cannot modify an area being edited in a dedicated buffer"))))) + (overlay-put overlay 'modification-hooks read-only) + (overlay-put overlay 'insert-in-front-hooks read-only) + (overlay-put overlay 'insert-behind-hooks read-only)) overlay)) (defun org-src--remove-overlay () @@ -872,11 +871,14 @@ Throw an error if there is no such buffer." (with-current-buffer (org-src--source-buffer) (undo-boundary) (goto-char beg) + ;; Temporarily disable read-only features of OVERLAY in order to + ;; insert new contents. + (delete-overlay overlay) (delete-region beg end) (when (org-string-nw-p edited-code) (insert edited-code)) (unless (bolp) (insert "\n")) - (move-overlay overlay beg (point)) - (save-buffer)))) + (save-buffer) + (move-overlay overlay beg (point))))) (defun org-edit-src-exit () "Kill current sub-editing buffer and return to source buffer." |