help-gnu-emacs
[Top][All Lists]
Advanced

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

Return to Marker


From: CarlC
Subject: Return to Marker
Date: Thu, 30 Jan 2003 17:38:39 GMT

I have a function that inserts some strings of text. Under normal
circumstances, I want point to be back at the original position. My problem
is that it only works part of the time, depending on where the original
point was. When it fails, it puts me at a point towards the end of the
buffer. I can't figure out why it works in some places and not in others. I
have tried save-excusion and get the same results. The real clincher, is
that it always works when I am debugging. I can press "c" as soon as I enter
the debugger, and it still works. The line of code is "(goto-char
custom-marker))" near the bottom of the function. It always seems to make it
to this code with the correct value of custom-marker. I am running GNU Emacs
21.2.1. Everything else in the function works great. Thanks for any help on
this.

(defun insert-cobol-file (file-id)
  "Insert COBOL file into source."
  (interactive "sFile id: ")
  (let ((searches (list
                   "DATA DIVISION."
                   "WORKING-STORAGE SECTION."
                   "SCREEN SECTION."
                   "PROCEDURE DIVISION"
                   "MAS-ERR SECTION."
                   "END.DC"
                   "PERFORM FILE-INIT"))
        (custom-marker (point-marker))
        (initwarn nil))
    (unwind-protect
        (progn
          (beginning-of-buffer)
          (let (err)
            (dolist (search searches err)
              (if (not (search-forward search nil t))
                  (error "Search failed: %s" search))))
          (beginning-of-buffer)
          (search-forward (pop searches))
          (previous-line 1)
          (beginning-of-line)
          (insert (format "\tCOPY \"UCOPY:%sFILE.SL\".\n" file-id))
          (search-forward (pop searches))
          (previous-line 1)
          (beginning-of-line)
          (insert (format "\tCOPY \"UCOPY:%sFILE.FD\".\n" file-id))
          (search-forward (pop searches))
          (previous-line 2)
          (beginning-of-line)
          (search-backward ".WS")
          (next-line 1)
          (beginning-of-line)
          (insert (format "\tCOPY \"UCOPY:%sFILE.WS\".\n" file-id))
          (search-forward (pop searches))
          (previous-line 1)
          (beginning-of-line)
          (insert (format "\tCOPY \"UCOPY:%sFILE.SS\".\n" file-id))
          (search-forward (pop searches))
          (search-forward ".")
          (backward-char)
          (insert (format ", %sFILE" file-id))
          (if (> (current-column) 79)
              (progn
                (backward-word 1)
                (delete-backward-char 1)
                (insert "\n\t\t")))
          (search-forward (pop searches))
          (previous-line 1)
          (beginning-of-line)
          (insert (format "\tCOPY \"UCOPY:%sFILE.DC\".\n" file-id))
          (search-forward (pop searches))
          (if (not (char-equal (following-char) ?\.))
              (setq initwarn (point)))
          (beginning-of-line)
          (if (char-equal (following-char) ?\*)
              (progn
                (setq initwarn (point))
                (forward-char 1)))
          (let ((temp (point)))
            (next-line 1)
            (beginning-of-line)
            (copy-region-as-kill temp (point))
            (yank)
            (previous-line 1)
            (search-forward "FILE")
            (delete-backward-char 4)
            (insert file-id))
          (end-of-buffer)
          (previous-line 1)
          (beginning-of-line)
;(debug)
          (insert (format "\tCOPY \"UCOPY:%sFILE.OP\".\n" file-id)))
      (goto-char custom-marker))
    (if initwarn
        (progn
          (set-mark custom-marker)
          (goto-char initwarn)
          (message "** WARNING ** FILE-INIT is not standard")))))





reply via email to

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