미니 버퍼에 현재 파일의 전체 경로를 표시하는 기능
emacs로 편집중인 파일의 전체 경로를 가져와야합니다.
- 그 기능이 있습니까?
- 그렇지 않다면 그것을 얻기위한 elisp 함수는 무엇일까요?
- 결과 (경로 이름)를 클립 보드에 복사하여 재사용 할 수있는 방법은 무엇입니까?
Mac OS X와 Aqumacs를 사용하고 있습니다.
(setq filepath (get-fullpath-current-file)) ???
(copy-to-clipboard 'filepath) ???
추가됨
(defun show-file-name () "미니 버퍼에 전체 경로 파일 이름을 표시합니다." (인터렉티브) (메시지 (버퍼 파일 이름)) (kill-new (파일-진실 이름 버퍼-파일-이름)) ) (global-set-key "\ C-cz" 'show-file-name)
내가 얻은 두 가지 대답을 결합하면 원하는 것을 얻을 수 있습니다. 답변 해 주셔서 감사합니다. 그리고 몇 가지 더 많은 질문.
- (file-truename)은 무엇입니까?
- 다른 앱에서 정보를 사용할 수 있도록 킬 링이 아닌 시스템 (OS)의 클립 보드에 경로 이름을 복사 할 수 있습니까?
buffer-file-name
파일의 전체 경로를 제공 하는 내장 함수 입니다.
가장 좋은 방법은 emacs 창에 항상 시스템 이름과 현재 편집중인 버퍼의 전체 경로를 표시하도록하는 것입니다.
(setq frame-title-format
(list (format "%s %%S: %%j " (system-name))
'(buffer-file-name "%f" (dired-directory dired-directory "%b"))))
다음과 같이 할 수도 있습니다.
(defun show-file-name ()
"Show the full path file name in the minibuffer."
(interactive)
(message (buffer-file-name)))
(global-set-key [C-f1] 'show-file-name) ; Or any other key you want
Jérôme Radix의 답변에서 빌리려면 현재 버퍼의 파일 경로를 빠르게 보려면 M-: buffer-file-name
.
내 트릭은 C-x C-f
파일을 여는 것과 같은 작업을 수행하는 것입니다. 미니 버프를 현재 파일 경로로 미리 채우고 C-g
종료합니다. M-: buffer-file-name
다른 어떤 방법보다 빠르지 만 훨씬 못 생겼습니다.
원하는 것을 직접 구현하는 방법은 다음과 같습니다.
(defun copy-full-path-to-kill-ring ()
"copy buffer's full path to kill ring"
(interactive)
(when buffer-file-name
(kill-new (file-truename buffer-file-name))))
즉, 미니 버퍼에있는 전체 경로를 얻을 수 있다는 것이 매우 유용하다는 것을 알았습니다. 이것이 제가 사용하는 것입니다.
(define-key minibuffer-local-completion-map "\C-r" 'resolve-sym-link)
(defun resolve-sym-link ()
"Try to resolve symbolic links into true paths."
(interactive)
(beginning-of-line)
(let* ((file (buffer-substring (point)
(save-excursion (end-of-line) (point))))
(file-dir (file-name-directory file))
(file-true-dir (file-truename file-dir))
(file-name (file-name-nondirectory file)))
(delete-region (point) (save-excursion (end-of-line) (point)))
(insert (concat file-true-dir file-name))))
And then if I want it in the clipboard, I just kill the line (C-a C-k). But we could easily copy the truename to the clipboard in the above command, just change the last line to be:
(insert (kill-new (concat file-true-dir file-name)))))
The new part is the call to 'kill-new
which puts the string in the kill ring.
No need for extra function, just
M-! pwd
I have the following code already in use for a long time. It copies the full file path to the kill ring when I press the middle mouse button on the buffer name in the mode-line. It copies just the buffer name to the kill-ring when I press shift-mouse-2 on the buffer-name in the mode-line.
(defun copy-buffer-file-name (event &optional bufName)
"Copy buffer file name to kill ring.
If no file is associated with buffer just get buffer name.
"
(interactive "eP")
(save-selected-window
(message "bufName: %S" bufName)
(select-window (posn-window (event-start event)))
(let ((name (or (unless bufName (buffer-file-name)) (buffer-name))))
(message "Saved file name \"%s\" in killring." name)
(kill-new name)
name)))
(define-key mode-line-buffer-identification-keymap [mode-line mouse-2] 'copy-buffer-file-name)
(define-key mode-line-buffer-identification-keymap [mode-line S-mouse-2] '(lambda (e) (interactive "e") (copy-buffer-file-name e 't)))
C-x C-d
, also callable via M-x list-directory
, will show you the directory for your current file, and you only need to hit the "Enter" key to clear the minibuffer. Additional details are available here.
Can I copy the path name to System(OS)'s clipboard, not the kill ring so that I can use the info with the other apps?
You can if you shell out to something like xclip (Linux), pbcopy (Mac), putclip (Cygwin).
I personally use wrapper scripts c
and p
for copy and paste respectively, the first reading from standard input, the latter writing to standard output. That way, this works on all my development platforms:
(shell-command (format "echo '%s' | c" buffer-file-name))
I find this more reliable and configurable than using the Emacs clipboard support. For example, my c
command copies the input to all 3 clipboards on Linux (primary, secondary, clipboard), so I can paste with either Ctrl-V or middle click.
C-x C-b
shows a list of buffers and the file path for each buffer where applicable.
C-u C-x C-b
lists buffers currently visiting files.
The simplest way and would be
(buffer-name)<(C-x)(C-e)> for the file name to appear in the echo area
(buffer-name)<(C-u)(C-x)(C-e)> would print the location <here>
Borrowing from Trey Jackson I came up with this:
(defun buffer-kill-path ()
"copy buffer's full path to kill ring"
(interactive)
(kill-new (buffer-file-name)))
You can find more information on site
copy-buffer-file-name-as-kill
from [0] does exactly what you need I think. It also has the option to copy just directory name, or just file name.
[0] http://www.emacswiki.org/emacs/download/buffer-extension.el
'IT story' 카테고리의 다른 글
io.sockets.emit과 broadcast의 차이점은 무엇입니까? (0) | 2020.09.02 |
---|---|
angularjs의 조건부 ng-include (0) | 2020.09.02 |
SQL Server에서는 언제 GO를 사용해야하며 언제 세미콜론을 사용해야합니까? (0) | 2020.09.02 |
복제 가능 Java 정보 (0) | 2020.09.02 |
jsonpath로 회원 수? (0) | 2020.09.02 |