mlf176f2 pushed a commit to branch externals/ergoemacs-mode in repository elpa.
commit 78eb28da4c95748f855f0acca7bc1f6645975a10 Author: Matthew L. Fidler <[email protected]> Date: Thu Jun 26 08:36:45 2014 -0500 Be more careful with links. Issue #247 --- ergoemacs-macros.el | 41 +++++++++++++++++++++++++++++++++++++++++ ergoemacs-shortcuts.el | 19 ++++++++++--------- 2 files changed, 51 insertions(+), 9 deletions(-) diff --git a/ergoemacs-macros.el b/ergoemacs-macros.el index a1eeb88..89738af 100644 --- a/ergoemacs-macros.el +++ b/ergoemacs-macros.el @@ -389,6 +389,47 @@ It says that `adjoin' from `cl' may be called at runtime, so use `(pushnew ,x ,place ,@plist)) (t `(add-to-list ',place ,x ,(plist-get plist ':test))))) +;;;###autoload +(defmacro ergoemacs-save-buffer-state (&rest body) + "Eval BODY, +then restore the buffer state under the assumption that no significant +modification has been made in BODY. A change is considered +significant if it affects the buffer text in any way that isn't +completely restored again. Changes in text properties like `face' or +`syntax-table' are considered insignificant. This macro allows text +properties to be changed, even in a read-only buffer. + +This macro should be placed around all calculations which set +\"insignificant\" text properties in a buffer, even when the buffer is +known to be writeable. That way, these text properties remain set +even if the user undoes the command which set them. + +This macro should ALWAYS be placed around \"temporary\" internal buffer +changes \(like adding a newline to calculate a text-property then +deleting it again\), so that the user never sees them on his +`buffer-undo-list'. + +However, any user-visible changes to the buffer \(like auto-newlines\) +must not be within a `ergoemacs-save-buffer-state', since the user then +wouldn't be able to undo them. + +The return value is the value of the last form in BODY. + +This was stole/modified from `c-save-buffer-state'" + `(let* ((modified (buffer-modified-p)) (buffer-undo-list t) + (inhibit-read-only t) (inhibit-point-motion-hooks t) + before-change-functions after-change-functions + deactivate-mark + buffer-file-name buffer-file-truename ; Prevent primitives checking + ; for file modification + ) + (unwind-protect + (progn ,@body) + (and (not modified) + (buffer-modified-p) + (set-buffer-modified-p nil))))) + + (provide 'ergoemacs-macros) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ergoemacs-macros.el ends here diff --git a/ergoemacs-shortcuts.el b/ergoemacs-shortcuts.el index 21036aa..8bb51cf 100644 --- a/ergoemacs-shortcuts.el +++ b/ergoemacs-shortcuts.el @@ -1743,10 +1743,11 @@ Setup C-c and C-x keys to be described properly.") (when (and (previous-single-property-change (point) 'keymap) (next-single-property-change (point) 'keymap)) ;; (ergoemacs-debug "Put into text properties") - (put-text-property - (previous-single-property-change (point) 'keymap) - (next-single-property-change (point) 'keymap) - 'keymap override-text-map))) + (ergoemacs-save-buffer-state + (put-text-property + (or (previous-single-property-change (point) 'keymap (current-buffer) (point-min)) (point-min)) + (or (next-single-property-change (point) 'keymap (current-buffer) (point-max)) (point-max)) + 'keymap override-text-map)))) (setq tmp-overlay (make-overlay (max (- (point) 1) (point-min)) (min (+ (point) 1) (point-max)))) (overlay-put tmp-overlay 'keymap lookup) @@ -1879,11 +1880,11 @@ The keymaps are: (overlay-put found 'keymap override-text-map) ;; Overlay not found; change text property ;; (ergoemacs-debug "Put into text properties") - (put-text-property - (previous-single-property-change (point) 'keymap) - (next-single-property-change (point) 'keymap) - 'keymap - override-text-map)) + (ergoemacs-save-buffer-state + (put-text-property + (or (previous-single-property-change (point) 'keymap (current-buffer) (point-min)) (point-min)) + (or (next-single-property-change (point) 'keymap (current-buffer) (point-max)) (point-max)) + 'keymap override-text-map))) ;; (ergoemacs-debug-keymap 'override-text-map) )))))
