4

I've written a helper function for mu4e to run checkpatch against a message. However I want to be easily able to switch between previous calls to checkpatch and this seems difficult with ido-read-file-name. This is my code so far:

;;
;; Checkpatch in emails
;;
(defvar my-checkpatch-script-history nil
  "History of checkpatch invocations.")

(defun my-mu4e-action-run-check-patch (msg)
  "Run checkpatch against the [patch] `MSG'."
  (let*
      ((ido-work-file-list my-checkpatch-script-history)
       (script (ido-read-file-name
                "Checkpatch Script: " (directory-file-name (or (car
                                                                ido-work-file-list)
                                                               default-directory)))))
    (setf my-checkpatch-script-history
        (cons script (delete script my-checkpatch-script-history)))
    ;; actual check patch handling...

However C-n/C-p cycle through previous directories instead of files. The code I use to specify directories to apply patches which works a lot more naturally:

(defun mu4e-action-git-apply-patch (msg)
  "Apply the git [patch] message."
  (let ((path (ido-read-directory-name "Target directory: "
                                       (car ido-work-directory-list)
                                       "~/" t)))
    (setf ido-work-directory-list
          (cons path (delete path ido-work-directory-list)))
    ;; actual apply-patch handling

Is this just a limitation of dealing with files rather than directories?

  • There's a lot of code in there that isn't relevant to the question. It seems to me the important part is just (ido-read-file-name "Checkpatch Script: " (directory-file-name (or (car ido-work-file-list) default-directory))). And what you want is to cycle thorough previous files instead of directories with C-p? – Malabarba Nov 14 '14 at 11:02
  • @Malabarba: I didn't think it was that much but I've deleted anyway to be clear. Yes I want to navigate in history through previous checkpatch invocations. – stsquad Nov 14 '14 at 13:32
  • If there's no built-in way to handle it, then modifying the main function (i.e., ido-read-file-name) to push the result into a variable of your choosing is an option. Or, if your prefer, append. – lawlist Nov 14 '14 at 15:06
2

ido-read-file-name already does save previously selected values in ido-file-history. However it does not allow saving in another variable which would allow keeping different histories for different uses of that function. You could work around this like so:

(defun YOUR-ido-read-file-name (prompt)
  (cl-letf (((symbol-function 'orig-ido-read-internal)
             (symbol-function 'ido-read-internal))
            ((symbol-function 'ido-read-internal)
             (lambda (item prompt hist &optional default require-match initial)
               (orig-ido-read-internal item prompt 'YOUR-ido-file-history
                                       default require-match initial))))
    (ido-read-file-name prompt)))

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.