all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Re: allout encryption and non-ascii characters - a patch
@ 2006-11-13 15:36 Ken Manheimer
  2006-11-15 16:34 ` Chong Yidong
  0 siblings, 1 reply; 2+ messages in thread
From: Ken Manheimer @ 2006-11-13 15:36 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 2715 bytes --]

this is a new version of my allout patch that enables topic encryption
of non-ascii characters.

added to the previous fix is recognition of cases where the non-ascii
encoding is present in text that is being encrypted, but not accounted
for by the buffer encoding.  hence, encryption would make the
non-ascii chars invisible to emacs during-write detection of alternate
encodings, and so the encoding might not be properly accommodated when
the text is decrypted.  in such cases, allout detects that the
encoding of the text during encryption is different from the buffer's
encoding, and prompts the user to offer to preserve the encoding as a
file-local-variable.

this will not handle multiple incompatable encodings in the same file,
but emacs doesn't handle that, anyway.  encryption can hide the fact
of multiple encodings, such that some encrypted text will not be
presented correctly when decoded, but there's nothing to be done there
other than warning the user.  allout doesn't do that, but i'm not sure
there's enough recourse in that situation to make it worth the while.

i've tested this with some japanese-shift-jis (david smith's 筆は剣より強い。)
and iso-2022-7bit (a fancy ' apostrophe) encoded text (in separate
files), with good results.  it's possible that there is some other,
unaccounted problem causing the failure david was seeing, but i
suspect this is it, and in any case these fixes are helpful, and
should be applied.

since kim connected my posting about the encoding quandry with my
prior patch, that patch has not been applied, and this patch
incorporates that one.  it would be valuable to have these fixes in
the version of allout that's released with the full emacs 22 release,
so i'm anxious not to miss that.

the patch and changelog entry are attached, the changelog entry alone
is included inline, below.

-- 
ken
ken.manheimer@gmail.com
http://myriadicity.net

2006-13-05  Ken Manheimer  <ken.manheimer@gmail.com>

	* allout.el (allout-doublecheck-at-and-shallower): Clarify
	docstring.
	(allout-inhibit-aberrance-doublecheck): Rename from
	allout-during-yank-processing.
	(allout-do-doublecheck): Track allout-inhibit-aberrance-doublecheck
	name change.
	(allout-ascend): Provide for unusual case where some topic after
	the first in file is at lower depth than the first.
	(allout-shift-in): Ensure the offspring of the new containing
	topic are exposed.
	(allout-encrypt-string): Preserve the coding-system of the text,
	according to that of the containing buffer.
	(allout-toggle-subtree-encryption): When the text being encrypted
	requires a different coding system than that prevailing in the
	buffer, offer to preserve the coding system using a file local
	var.

[-- Attachment #2: allout-patch.txt --]
[-- Type: text/plain, Size: 9238 bytes --]

Index: allout.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/allout.el,v
retrieving revision 1.88
diff -u -u -r1.88 allout.el
--- allout.el	6 Nov 2006 02:51:45 -0000	1.88
+++ allout.el	13 Nov 2006 07:06:25 -0000
@@ -895,14 +895,9 @@
   "Validate apparent topics of this depth and shallower as being non-aberrant.
 
 Verified with `allout-aberrant-container-p'.  This check's usefulness is
-limited to shallow prospects, because the determination of aberrance
-depends on the mistaken item being followed by a legitimate item of
-excessively greater depth.
-
-A level of 2 is safest, so that yanks, which must ignore
-aberrance while rectifying the yanked text to their new location,
-is least likely to be fooled by aberrant topics in the yanked
-text.")
+limited to shallow depths, because the determination of aberrance
+is according to the mistaken item being followed by a legitimate item of
+excessively greater depth.")
 ;;;_   X allout-reset-header-lead (header-lead)
 (defun allout-reset-header-lead (header-lead)
   "*Reset the leading string used to identify topic headers."
@@ -1511,13 +1506,18 @@
     (goto-char (cadr allout-after-save-decrypt))
     (setq allout-after-save-decrypt nil))
   )
-;;;_   = allout-during-yank-processing nil
-;; XXX allout yanks adjust the level of the topic being pasted to that of
-;; their target location.  aberrance must be inhibited to allow that
-;; reconciliation.  (this means that actually aberrant topics won't be
-;; treated specially while being pasted.)
-(defvar allout-during-yank-processing nil
-  "Internal state, inhibits aberrance doublecheck while adjusting yanks.")
+;;;_   = allout-inhibit-aberrance-doublecheck nil
+;; In some exceptional moments, disparate topic depths need to be allowed
+;; momentarily, eg when one topic is being yanked into another and they're
+;; about to be reconciled.  let-binding allout-inhibit-aberrance-doublecheck
+;; prevents the aberrance doublecheck to allow, eg, the reconciliation
+;; processing to happen in the presence of such discrepancies.  It should
+;; almost never be needed, however.
+(defvar allout-inhibit-aberrance-doublecheck nil
+  "Internal state, for momentarily inhibits aberrance doublecheck.
+
+This should only be momentarily let-bound non-nil, not set
+non-nil in a lasting way.")
 
 ;;;_ #2 Mode activation
 ;;;_  = allout-explicitly-deactivated
@@ -2212,7 +2212,7 @@
   (and
    ;; presume integrity of outline and yanked content during yank - necessary,
    ;; to allow for level disparity of yank location and yanked text:
-   (not allout-during-yank-processing)
+   (not allout-inhibit-aberrance-doublecheck)
    ;; allout-doublecheck-at-and-shallower is ceiling for doublecheck:
    (<= allout-recent-depth allout-doublecheck-at-and-shallower)))
 ;;;_     > allout-aberrant-container-p ()
@@ -2891,7 +2891,15 @@
   "Ascend one level, returning t if successful, nil if not."
   (prog1
       (if (allout-beginning-of-level)
-          (allout-previous-heading))
+          (let ((bolevel (point))
+                (bolevel-depth allout-recent-depth))
+            (allout-previous-heading)
+            (if (< allout-recent-depth bolevel-depth)
+                allout-recent-depth
+              ;; some topic after file's first is at lower depth than first:
+              (goto-char bolevel)
+              (allout-depth)
+              nil)))
     (if (interactive-p) (allout-end-of-prefix))))
 ;;;_   > allout-descend-to-depth (depth)
 (defun allout-descend-to-depth (depth)
@@ -3502,8 +3510,6 @@
 
 If OFFER-RECENT-BULLET is true, offer to use the bullet of the prior sibling.
 
-Runs
-
 Nuances:
 
 - Creation of new topics is with respect to the visible topic
@@ -4145,7 +4151,10 @@
                      (> (1+ current-depth)
                         (1+ predecessor-depth)))
                 (error (concat "Disallowed shift deeper than"
-                               " containing topic's children."))))))
+                               " containing topic's children."))
+              (allout-back-to-current-heading)
+              (if (< allout-recent-depth (1+ current-depth))
+                  (allout-show-children))))))
     (let ((where (point)))
       (allout-rebullet-topic 1 (and (> arg 1) 'sans-offspring))
       (run-hook-with-args 'allout-structure-shifted-hook arg where))))
@@ -4382,13 +4391,12 @@
 					; region around subject:
   (if (< (allout-mark-marker t) (point))
       (exchange-point-and-mark))
-  (let* ( ;; inhibit aberrance doublecheck while reconciling disparate pastes:
-         (allout-during-yank-processing t)
-         (subj-beg (point))
+  (let* ((subj-beg (point))
          (into-bol (bolp))
          (subj-end (allout-mark-marker t))
          ;; 'resituate' if yanking an entire topic into topic header:
-         (resituate (and (allout-e-o-prefix-p)
+         (resituate (and (let ((allout-inhibit-aberrance-doublecheck t))
+                           (allout-e-o-prefix-p))
                          (looking-at allout-regexp)
                          (allout-prefix-data)))
          ;; `rectify-numbering' if resituating (where several topics may
@@ -4396,7 +4404,7 @@
          (rectify-numbering (or resituate
                                 (and into-bol (looking-at allout-regexp)))))
     (if resituate
-                                        ; The yanked stuff is a topic:
+        ;; Yanking a topic into the start of a topic - reconcile to fit:
         (let* ((inhibit-field-text-motion t)
                (prefix-len (if (not (match-end 1))
                                1
@@ -4466,7 +4474,8 @@
                    (progn
                      (delete-region (point) (+ (point)
                                                prefix-len
-                                               (- adjust-to-depth subj-depth)))
+                                               (- adjust-to-depth
+                                                  subj-depth)))
                                         ; and delete residual subj
                                         ; prefix digits and space:
                      (while (looking-at "[0-9]") (delete-char 1))
@@ -5757,7 +5766,7 @@
                        " shift it in to make it encryptable")))
 
     (let* ((allout-buffer (current-buffer))
-           ;; Asses location:
+           ;; Assess location:
            (bullet-pos allout-recent-prefix-beginning)
            (after-bullet-pos (point))
            (was-encrypted
@@ -5791,7 +5800,29 @@
                       '(symmetric nil)))
            (for-key-type (car key-info))
            (for-key-identity (cadr key-info))
-           (fetch-pass (and fetch-pass (member fetch-pass '(16 (16))))))
+           (fetch-pass (and fetch-pass (member fetch-pass '(16 (16)))))
+           (was-coding-system buffer-file-coding-system))
+
+      (when (not was-encrypted)
+        ;; ensure that non-ascii chars pending encryption are noticed before
+        ;; they're encrypted, so the coding system is set to accomodate
+        ;; them.
+        (setq buffer-file-coding-system
+              (select-safe-coding-system subtree-beg subtree-end))
+        ;; if the coding system for the text being encrypted is different
+        ;; than that prevailing, then there a real risk that the coding
+        ;; system can't be noticed by emacs when the file is visited.  to
+        ;; mitigate that, offer to preserve the coding system using a file
+        ;; local variable.
+        (if (and (not (equal buffer-file-coding-system
+                             was-coding-system))
+                 (yes-or-no-p
+                  (format (concat "Register coding system %s as file local"
+                                  " var?  Necessary when only encrypted text"
+                                  " is in that coding system. ")
+                          buffer-file-coding-system)))
+            (allout-adjust-file-variable "buffer-file-coding-system"
+                                         buffer-file-coding-system)))
 
       (setq result-text
             (allout-encrypt-string subject-text was-encrypted
@@ -5880,6 +5911,10 @@
                                       target-prompt-id
                                     (or (buffer-file-name allout-buffer)
                                         target-prompt-id))))
+         (encoding (with-current-buffer allout-buffer
+                     buffer-file-coding-system))
+         (multibyte (with-current-buffer allout-buffer
+                     enable-multibyte-characters))
          (strip-plaintext-regexps
           (if (not decrypt)
               (allout-get-configvar-values
@@ -5916,6 +5951,13 @@
 
           (insert text)
 
+          ;; convey the text characteristics of the original buffer:
+          (set-buffer-multibyte multibyte)
+          (when encoding
+            (set-buffer-file-coding-system encoding)
+            (if (not decrypt)
+                (encode-coding-region (point-min) (point-max) encoding)))
+
           (when (and strip-plaintext-regexps (not decrypt))
             (dolist (re strip-plaintext-regexps)
               (let ((re (if (listp re) (car re) re))

[-- Attachment #3: ChangeLog-entry.txt --]
[-- Type: text/plain, Size: 808 bytes --]

2006-13-05  Ken Manheimer  <ken.manheimer@gmail.com>

	* allout.el (allout-doublecheck-at-and-shallower): Clarify
	docstring.
	(allout-inhibit-aberrance-doublecheck): Rename from
	allout-during-yank-processing.
	(allout-do-doublecheck): Track allout-inhibit-aberrance-doublecheck
	name change.
	(allout-ascend): Provide for unusual case where some topic after
	the first in file is at lower depth than the first.
	(allout-shift-in): Ensure the offspring of the new containing
	topic are exposed.
	(allout-encrypt-string): Preserve the coding-system of the text,
	according to that of the containing buffer.
	(allout-toggle-subtree-encryption): When the text being encrypted
	requires a different coding system than that prevailing in the
	buffer, offer to preserve the coding system using a file local
	var.

[-- Attachment #4: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: allout encryption and non-ascii characters - a patch
  2006-11-13 15:36 allout encryption and non-ascii characters - a patch Ken Manheimer
@ 2006-11-15 16:34 ` Chong Yidong
  0 siblings, 0 replies; 2+ messages in thread
From: Chong Yidong @ 2006-11-15 16:34 UTC (permalink / raw)
  Cc: David Smith, Kim F. Storm, Emacs-Devel

"Ken Manheimer" <ken.manheimer@gmail.com> writes:

> this is a new version of my allout patch that enables topic encryption
> of non-ascii characters.

I've checked it in; thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-11-15 16:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-11-13 15:36 allout encryption and non-ascii characters - a patch Ken Manheimer
2006-11-15 16:34 ` Chong Yidong

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.