I included save-excursion to preserve the cursor position, but when the buffer is evaluated, the cursor still moves to the last evaluated block.
save-excursion
seems to have restrictions if one evaluates code that changes buffer or window. How can I modify this so that the cursor keeps at its original position in the calling buffer?
(defun queval (sel)
(interactive (let ((qsel '("eval-wd-buffer"
"eval-nr-buffer"
"eval-buffer"
"eval-defun"
"eval-last-sexp")))
(list (completing-read "Evaluate: " qsel nil t))))
(cond ((string= sel "eval-wd-buffer")
(save-excursion
(save-restriction
(widen)
(eval-buffer))))
((string= sel "eval-nr-buffer")
(save-excursion (eval-buffer)))
((string= sel "eval-buffer")
(save-excursion
(eval-buffer)))
((string= sel "eval-defun")
(eval-defun nil))
((string= sel "eval-last-sexp")
(eval-last-sexp nil))))
Have tried to store the original cursor point, but the problem persists.
(defun qeval (sel)
(interactive (let ((qsel '("eval-wd-buffer"
"eval-nr-buffer"
"eval-buffer"
"eval-defun"
"eval-last-sexp")))
(list (completing-read "Evaluate: " qsel nil t))))
(let ((initial-buffer (current-buffer))
(initial-point (point)))
(cond ((string= sel "eval-wd-buffer")
(save-excursion
(save-restriction
(widen)
(eval-buffer))))
((string= sel "eval-nr-buffer")
(save-excursion
(eval-buffer)))
((string= sel "eval-buffer")
(save-excursion
(eval-buffer)))
((string= sel "eval-defun")
(eval-defun nil))
((string= sel "eval-last-sexp")
(eval-last-sexp nil)))
;; Restore buffer and point explicitly
(when (buffer-live-p initial-buffer)
(switch-to-buffer initial-buffer)
(goto-char initial-point))))
This is what I have after, The cursor point gets changed to the last code chunk that ends with (message "Done"))
.
(defun graficos-htbl (htable &optional bfrn)
"Print HTABLE to the buffer BFRN."
(let* ( (bfname (or bfrn "Questorium Hash Table"))
(dbuffer (get-buffer-create (concat "𒆳 " bfname))) )
(with-current-buffer dbuffer
(face-remap-add-relative 'default :background "blue")
(insert "\n Hash Table \n\n")
(maphash
(lambda (key value)
(let* ( (start (point)) )
;; Insert key
(insert (format " ━ %-8s" key))
;; Colourise key
(add-text-properties start (point)
`(face (:foreground "green")))
;; Insert associated value
(insert (format "\n %s\n" value))))
htable))))
(defun graficos-fpln-test (fpln anctr &optional bfrn)
"Print the waypoint and validity for each entry in ALIST in a new
buffer. Waypoints will be colored red if valid and green if invalid."
(let* ( (bfname (or bfrn "Graficos Fpln Test"))
(dbuffer (get-buffer-create (concat "𒆳 " bfname))) )
(with-current-buffer dbuffer
(erase-buffer) ;; Clear the buffer before writing
;; Set the background color to blue for the buffer
(face-remap-add-relative 'default :background "blue")
(insert " " bfname "\n\n Waypoint Annunciator \n\n")
(insert (format " [Fpln] %s"
(if (hash-table-p fpln) "hash-table" "alist")))
(insert (format " [Anctr] %s\n\n"
(if (hash-table-p anctr) "hash-table" "alist")))
;; Print Waypoints and corresponding directory paths
(cond
;; ---------------------------------------------------
;; HASH-TABLE CONDITION
((hash-table-p fpln)
(maphash
(lambda (waypt dir-path)
(let* ( (wpt-monitor (gethash waypt anctr))
(start (point)) )
;; Insert waypoint
(insert (format " ━ %-8s" waypt))
;; Apply color based on validity
(add-text-properties start (point)
`(face (:foreground ,(if wpt-monitor "red" "green"))))
;; Insert validity text
(insert (format "\n %s\n" dir-path))) )
fpln))
;; -------------------------------------------------------
;; ALIST CONDITION
((listp fpln)
(dolist (entry fpln)
(let* ( (waypt (car entry))
(dir-path (graficos-fpln-waypt waypt fpln))
(wpt-monitor (cdr (assoc waypt anctr)))
(start (point)) )
;; Insert waypoint
(insert (format " ━ %-8s" waypt))
;; Apply color based on validity
(add-text-properties start (point)
`(face (:foreground ,(if wpt-monitor "red" "green"))))
;; Insert validity text
(insert (format "\n %s\n" dir-path)))) ))
;; ---------------------------------------------------------
;; Move to beginning of buffer
(goto-char (point-min)))
;; Display the buffer
(switch-to-buffer dbuffer)))
(let ( (input-table (make-hash-table :test 'equal)) )
;; Add some directories (replace these with real paths on your
;; system)
(puthash "home-dir" "/home/hagbard" input-table)
(puthash "docs-dir" "/home/hagbard/Documents" input-table)
(puthash "fake-dir" "/non/existing/path" input-table)
(graficos-htbl input-table "HASH TABLE")
(let ( (anctr (graficos-fpln-anctr input-table)) )
(graficos-htbl anctr "ANCTR")
(graficos-fpln-test input-table anctr "Output Table")
(message "Done"))
(message "Done"))
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4