LINUX.ORG.RU

Прикрутить ido к promt'у

 


0

1

Стырил я с emacswiki такую функцию:

(defun my-insert-file-name (filename &optional args)
  "Insert name of file FILENAME into buffer after point.
  
  Prefixed with \\[universal-argument], expand the file name to
  its fully canocalized path.  See `expand-file-name'.
  
  Prefixed with \\[negative-argument], use relative path to file
  name from current directory, `default-directory'.  See
  `file-relative-name'.
  
  The default with no prefix is to insert the file name exactly as
  it appears in the minibuffer prompt."
  ;; Based on insert-file in Emacs -- ashawley 20080926
  (interactive "*fInsert file name: \nP")
  (cond ((eq '- args)
         (insert (file-relative-name filename)))
        ((not (null args))
         (insert (expand-file-name filename)))
        (t
         (insert filename))))

Можно ли приделать ней prompt как у ido-mode?

★★★★★

Ответ на: комментарий от Bad_ptr

Ну как бэ ido-mode позволяет вводить в минибуфере pathname с комплитом, а остальное в документации к функции.

ados ★★★★★
() автор топика
Ответ на: комментарий от ados

я из этой документации нифига не понял зачем такая кракозябра может понадобиться.
Но, если тебе надо прочитать из минибуфера имя файла, используй функцию `read-file-name'. Если у тебя включено `ido-mode', то оно автоматически переназначается на `ido-read-file-name'.

Bad_ptr ★★★★★
()
Последнее исправление: Bad_ptr (всего исправлений: 1)
Ответ на: комментарий от Bad_ptr

Спасибо. Так я сабж пропатчил:

(defun my-insert-file-name (&optional args)
  "Insert name of file FILENAME into buffer after point.
  
  Prefixed with \\[universal-argument], expand the file name to
  its fully canocalized path.  See `expand-file-name'.
  
  Prefixed with \\[negative-argument], use relative path to file
  name from current directory, `default-directory'.  See
  `file-relative-name'.
  
  The default with no prefix is to insert the file name exactly as
  it appears in the minibuffer prompt."
  ;; Based on insert-file in Emacs -- ashawley 20080926
  (interactive "P")
  (let ((filename (ido-read-file-name "Insert file name: ")))
    (cond ((eq '- args)
           (insert (file-relative-name filename)))
          ((not (null args))
           (insert filename))
          (t
           (insert (file-name-nondirectory filename))))))
ados ★★★★★
() автор топика
Ответ на: комментарий от ados

ладно, уговорил

(defun my-insert-file-name (filename &optional args)
  (interactive (list (read-file-name "Insert filename: ") current-prefix-arg))
  (cond ((eq '- args)
         (insert (file-relative-name filename)))
        ((not (null args))
         (insert (expand-file-name filename)))
        (t
         (insert filename))))
Bad_ptr ★★★★★
()
Последнее исправление: Bad_ptr (всего исправлений: 1)
Ответ на: комментарий от ados

Добавил ещё свистелок:

(defun my-insert-file-name (&optional args)
  (interactive "P")
  (let ((filename (if (and (listp args)
                           (eq 16
                               (car args)))
                      (ido-read-directory-name "Insert directory name: ")
                    (ido-read-file-name "Insert file name: "))))
    (cond ((eq '- args)
           (insert (file-relative-name filename)))
          ((not (null args))
           (insert filename))
          (t
           (insert (file-name-nondirectory filename))))))
ados ★★★★★
() автор топика
Ответ на: комментарий от ados

Блин, с обработкой аргументов для директорий набыдлокодил.

Для директорий создал отдельную функцию.

ados ★★★★★
() автор топика
Последнее исправление: ados (всего исправлений: 1)
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.