emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: last character on line different when behind invis text?


From: Richard Stallman
Subject: Re: last character on line different when behind invis text?
Date: Sat, 07 Sep 2002 06:29:08 -0400

Please try this replacement function.  The code does what the doc strings
says.  Whether that makes for correct behavior I am not sure.



(defun forward-visible-line (arg)
  "Move forward by ARG lines, ignoring currently invisible newlines only.
If ARG is negative, move backward -ARG lines.
If ARG is zero, move to the beginning of the current line."
  (condition-case nil
      (if (> arg 0)
          (progn
            (while (> arg 0)
              (or (zerop (forward-line 1))
                  (signal 'end-of-buffer nil))
              ;; If the newline we just skipped is invisible,
              ;; don't count it.
              (let ((prop
                     (get-char-property (1- (point)) 'invisible)))
                (if (if (eq buffer-invisibility-spec t)
                        prop
                      (or (memq prop buffer-invisibility-spec)
                          (assq prop buffer-invisibility-spec)))
                    (setq arg (1+ arg))))
              (setq arg (1- arg)))
            ;; If invisible text follows, and it is a number of complete lines,
            ;; skip it.
            (let ((opoint (point)))
              (while (and (not (eobp))
                          (let ((prop
                                 (get-char-property (point) 'invisible)))
                            (if (eq buffer-invisibility-spec t)
                                prop
                              (or (memq prop buffer-invisibility-spec)
                                  (assq prop buffer-invisibility-spec)))))
                (goto-char
                 (if (get-text-property (point) 'invisible)
                     (or (next-single-property-change (point) 'invisible)
                         (point-max))
                   (next-overlay-change (point)))))
              (unless (bolp)
                (goto-char opoint))))
        (let ((first t))
          (while (or first (< arg 0))
            (if (zerop arg)
                (beginning-of-line)
              (or (zerop (forward-line -1))
                  (signal 'beginning-of-buffer nil)))
            ;; If the newline we just moved to is invisible,
            ;; don't count it.
            (unless (bobp)
              (let ((prop
                     (get-char-property (1- (point)) 'invisible)))
                (if (if (eq buffer-invisibility-spec t)
                        prop
                      (or (memq prop buffer-invisibility-spec)
                          (assq prop buffer-invisibility-spec)))
                    (setq arg (1+ arg)))))
            (setq first nil)
            (setq arg (1+ arg)))
          ;; If invisible text follows, and it is a number of complete lines,
          ;; skip it.
          (let ((opoint (point)))
            (while (and (not (bobp))
                        (let ((prop
                               (get-char-property (1- (point)) 'invisible)))
                          (if (eq buffer-invisibility-spec t)
                              prop
                            (or (memq prop buffer-invisibility-spec)
                                (assq prop buffer-invisibility-spec)))))
              (goto-char
               (if (get-text-property (1- (point)) 'invisible)
                   (or (previous-single-property-change (point) 'invisible)
                       (point-min))
                 (previous-overlay-change (point)))))
            (unless (bolp)
              (goto-char opoint)))))
    ((beginning-of-buffer end-of-buffer)
     nil)))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]