branch: elpa/logview
commit 75c494559f4fef0eb3eb69b62495568bc4ec49b1
Author: Paul Pogonyshev <pogonys...@gmail.com>
Commit: Paul Pogonyshev <pogonys...@gmail.com>

    Reimplement "narrowed unlocking" using the public macro, since we don't 
need to support Emacs snapshots anymore and because they are hell-bent on 
renaming internal support functions every other month.
---
 logview.el      | 36 +++++++++++++-----------------------
 test/logview.el | 19 +++++++++++++++++++
 2 files changed, 32 insertions(+), 23 deletions(-)

diff --git a/logview.el b/logview.el
index 8e199d5617..610adb5b59 100644
--- a/logview.el
+++ b/logview.el
@@ -921,27 +921,19 @@ inside BODY.  In most cases (also if not sure) you should 
use
 macro `logview--std-temporarily-widening' instead."
   (declare (indent 0) (debug t))
   `(save-restriction
-     (logview--do-widen)
-     ,@body))
+     ;; {LOCKED-NARROWING}
+     ;; "Hurr-durr, mah security, you cannot unlock without knowing the tag."  
Try all
+     ;; tags I could find in Emacs source code.  Normally this should be 
enough, but there
+     ;; is obviously no guarantee as macro `with-restriction' is part of 
public Elisp
+     ;; interface now.
+     (without-restriction
+       :label 'long-line-optimizations-in-fontification-functions
+       (without-restriction
+         :label 'long-line-optimizations-in-command-hooks
+         (logview--do-widen)
+         ,@body))))
 
 (defun logview--do-widen ()
-  ;; {LOCKED-NARROWING}
-  ;; "Hurr-durr, mah security, you cannot unlock without knowing the tag."  
Try all tags I
-  ;; could find in Emacs source code.  Normally this should be enough, but 
there is
-  ;; obviously no guarantee with function `narrowing-lock' being part of 
public Lisp
-  ;; interface.
-  ;;
-  ;; Additionally, they had to rename everything in this retarded crap.  Twice 
so far.
-  (cond ((fboundp 'internal--unlabel-restriction)
-         (internal--unlabel-restriction 
'long-line-optimizations-in-fontification-functions)
-         (internal--unlabel-restriction 
'long-line-optimizations-in-command-hooks))
-        ((fboundp 'internal--unlock-narrowing)
-         (internal--unlock-narrowing 
'long-line-optimizations-in-fontification-functions)
-         (internal--unlock-narrowing 
'long-line-optimizations-in-command-hooks))
-        ((fboundp 'narrowing-unlock)
-         (narrowing-unlock 'fontification-functions)
-         (narrowing-unlock 'pre-command-hook)
-         (narrowing-unlock 'post-command-hook)))
   (widen)
   ;; If still not widened, then it is better to fail hard now than to face an 
arbitrary
   ;; and hard to predict failure later.  In particular, an infinite loop in 
fontification
@@ -1218,10 +1210,8 @@ successfully.")
   ;; allow us to unlock this shit sometimes, but not the earlier, there we can 
only set
   ;; this variable in hope this prevents it from ever happening.
   ;;
-  ;; See what `logview--do-widen' does with these functions.  I don't see a 
way to test
-  ;; that in an automated way, because internally Emacs activates this 
optimization only
-  ;; in displaying code, which is never used in such setup at all.
-  (when (and (boundp 'long-line-threshold) (not (fboundp 
'internal--unlabel-restriction)) (not (fboundp 'internal--unlock-narrowing)) 
(not (fboundp 'narrowing-unlock)))
+  ;; See how `logview--temporarily-widening' uses `without-restriction'.
+  (when (and (boundp 'long-line-threshold) (not (fboundp 
'without-restriction)))
     (setq-local long-line-threshold nil))
   (logview--update-keymap)
   (add-hook 'read-only-mode-hook #'logview--update-keymap nil t)
diff --git a/test/logview.el b/test/logview.el
index 14d0ebecd4..93895d629d 100644
--- a/test/logview.el
+++ b/test/logview.el
@@ -27,6 +27,25 @@
 (defvar inhibit-message)
 
 
+(ert-deftest logview--temporarily-widening ()
+  (with-temp-buffer
+    (insert "foo bar baz")
+    ;; {LOCKED-NARROWING}
+    ;; Emulate the retarded locked narrowing with "standard" tags.  If someone 
uses a
+    ;; custom tag, Logview will have to fail, because it won't be able to work 
without
+    ;; full buffer access, but oh well, this is Emacs for you.  They allowed 
peasants to
+    ;; unlock at least something.
+    ;;
+    ;; Testing without emulation, with real Emacs-imposed locking seems 
unfeasible, since
+    ;; relevant font-locking code is not activated in batch mode.
+    (dolist (tag '(long-line-optimizations-in-fontification-functions 
long-line-optimizations-in-command-hooks))
+      (with-restriction 5 8
+        :label tag
+        (should (string= (buffer-string) "bar"))
+        (logview--temporarily-widening
+          (should (string= (buffer-string) "foo bar baz")))))))
+
+
 (defun logview--test-display-warning-advice (&rest arguments)
   (error "Warning elevated to an error: %S" arguments))
 

Reply via email to