1

Here is what I wish to achieve:

(defun rcd-edit-value (value)
      (let ((file (make-temp-file "rcd-db-" nil ".txt" value)))
        (find-file file)
        (string-from-file)))

(defun string-from-file (file)
  "Return file content."
  (with-temp-buffer
    (insert-file-contents file)
    (buffer-string)))

However (find-file file) is not blocking the function, function returns before the file was edited and killed. I would like to edit the file, and return, so that value is returned back, and that temporary file remains on the disk.

migrated from serverfault.com Oct 10 '18 at 17:45

This question came from our site for system and network administrators.

  • (string-from-file file) should be correct – Mr. Rosario Maddox Oct 10 '18 at 17:51
  • 2
    Can you explain the larger problem you're trying to solve? There may be a more direct approach to accomplishing your goal. – Tyler Oct 10 '18 at 20:05
  • I can edit values in mini-buffer when they are not larger values. But I need to edit database fields that are text articles, notes, and descriptions. I am fetching database field and wish to edit it, and that editing returns the value of edited string back, so that I can feed it back into database. My another not successful attempt is here: pastebin.com/BvdqRRpG and it will work when I become able to set variable based on edited string. – Mr. Rosario Maddox Oct 10 '18 at 20:11
  • A common approach to this kind of task is to create a temporary buffer, insert the starting text (the values from the database here), and set up a minor mode with a key bound to a function that signals you're finished editing. So instead of calling string-from-file immediately/automatically, you'd bind it to a key in your minor mode, which the user presses when they're done editing. Magit does this for commit messages, and mu4e does it for email messages. It might be easier than what you're trying to do. – Tyler Oct 10 '18 at 20:43
  • This is my another attempt debbugs.gnu.org/cgi/bugreport.cgi?bug=33007 – Mr. Rosario Maddox Oct 10 '18 at 21:06
1
;;; edited from https://raw.githubusercontent.com/deestan/emacs/master/emacs-goodies-el/miniedit.el
(defun edit-string (value)
  "Edits string and returns it"
  (let ((this-buffer (buffer-name))
        (new-value value)
        (buffy "*edit-string*"))
    (save-excursion
      (switch-to-buffer buffy)
      (set-buffer buffy)
      (text-mode)
      (local-set-key (kbd "C-c C-c") 'exit-recursive-edit)
      (if (stringp value) (insert value))
      (message "When you're done editing press C-c C-c or C-M-c to continue.")
      (unwind-protect
          (recursive-edit)
        (if (get-buffer-window buffy)
            (progn
              (setq new-value (buffer-substring (point-min) (point-max)))
              (kill-buffer buffy))))
      (switch-to-buffer this-buffer)
      new-value)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.