Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Folding of origami-markers-parser with unbalanced sizes displays incorrect. #80

Open
peterpaul opened this issue Dec 11, 2018 · 0 comments

Comments

@peterpaul
Copy link

peterpaul commented Dec 11, 2018

I'm using origami for a major mode I'm working on, where i use a very simple origami-markers-parser.
However the sizes of the begin and end marker strings are different, and when closing all the nodes it produces unexpected results.

For example

  • with (origami-markers-parser "12" "7890") on the string 1234567890 i expect 12...7890, but see 1234...7890
  • with (origami-markers-parser "abcd" "lm") on the string abcdefghijklm i expect abcd...lm, but see ab...lm

Both scenarios can be reproduced by the code at the end of this description (paste in *scratch* and M-x eval-buffer.

I looked in the code, and there appears to be a one line fix in origami-parsers.el

modified   origami-parsers.el
@@ -135,7 +135,7 @@ position in the CONTENT."
                                ((equal (caar positions) close)
                                 (if beg
                                     (progn ;close with no children
-                                      (setq acc (cons (funcall create beg (cdar positions) (length close) nil)
+                                      (setq acc (cons (funcall create beg (cdar positions) (length open) nil)
                                                       acc))
                                       (setq positions (cdr positions))
                                       (setq beg nil))

If needed I can create a pull-request with this fix. I don't know whether it breaks any other scenario.

Here's the code to reproduce the issue:

(require 'origami)
(define-derived-mode test-mode
  text-mode "test"
  "Major mode for test.
    \\{test-mode-map}"
  (setq case-fold-search nil))
(defun do-nothing () nil)
(define-key test-mode-map [down-mouse-3] 'do-nothing)

(map-put origami-parser-alist 'test-mode (origami-markers-parser "12" "7890"))

(let* ((buf (get-buffer-create "test1")))
  (switch-to-buffer buf)
  (with-current-buffer buf
    (test-mode)
    (origami-mode 1)
    (insert "1234567890")
    (origami-close-all-nodes buf)))
;; expected "12...7890", actual "1234...7890"

(map-put origami-parser-alist 'test-mode (origami-markers-parser "abcd" "lm"))

(let* ((buf (get-buffer-create "test2")))
  (switch-to-buffer buf)
  (with-current-buffer buf
    (test-mode)
    (origami-mode 1)
    (insert "abcdefghijklm")
    (origami-close-all-nodes buf)))
;; expected "abcd...lm", actual "ab...lm"
@peterpaul peterpaul changed the title Folding of origami-markers-parser with unbalanced sizes displays wrongly. Folding of origami-markers-parser with unbalanced sizes displays incorrect. Dec 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant