Emacs를 사용하여 현재 날짜와 시간을 파일에 어떻게 삽입 할 수 있습니까?
현재 날짜와 시간을 파일의 텍스트 버퍼에 삽입하기 위해 Emacs에서 어떤 명령을 사용할 수 있습니까?
(예를 들어, 메모장에서 동등한 기능은 단순히 메모장의 유일한 유용한 기능인 F5를 누르는 것입니다!)
C-u M-! date
.emacs 파일을 넣으십시오.
;; ====================
;; insert date and time
(defvar current-date-time-format "%a %b %d %H:%M:%S %Z %Y"
"Format of date to insert with `insert-current-date-time' func
See help of `format-time-string' for possible replacements")
(defvar current-time-format "%a %H:%M:%S"
"Format of date to insert with `insert-current-time' func.
Note the weekly scope of the command's precision.")
(defun insert-current-date-time ()
"insert the current date and time into current buffer.
Uses `current-date-time-format' for the formatting the date/time."
(interactive)
(insert "==========\n")
; (insert (let () (comment-start)))
(insert (format-time-string current-date-time-format (current-time)))
(insert "\n")
)
(defun insert-current-time ()
"insert the current time (1-week scope) into the current buffer."
(interactive)
(insert (format-time-string current-time-format (current-time)))
(insert "\n")
)
(global-set-key "\C-c\C-d" 'insert-current-date-time)
(global-set-key "\C-c\C-t" 'insert-current-time)
다음 짧은 스 니펫을 사용했습니다.
(defun now ()
"Insert string for the current time formatted like '2:34 PM'."
(interactive) ; permit invocation in minibuffer
(insert (format-time-string "%D %-I:%M %p")))
(defun today ()
"Insert string for today's date nicely formatted in American style,
e.g. Sunday, September 17, 2000."
(interactive) ; permit invocation in minibuffer
(insert (format-time-string "%A, %B %e, %Y")))
원래 journal.el 에서 왔습니다.
삽입 날짜 :
M-x org-time-stamp
날짜 시간 삽입 :
C-u M-x org-time-stamp
이 명령에 대한 전역 키를 바인딩 할 수 있습니다.
org-mode
의 방법은 매우 사용자 친화적이며 달력에서 날짜를 선택할 수 있습니다.
yasnippet 을 설치 하면 "시간"과 탭 키를 입력 할 수 있으며 그 외에도 더 많은 작업을 수행 할 수 있습니다. current-time-string
백그라운드에서 호출하기 만하면을 사용하여 서식을 제어 할 수 있습니다 format-time-string
.
여기 당신이 요청한 것을 수행하는 내가 얼마 전에 작성한 패키지가 있습니다.
http://github.com/rmm5t/insert-time.el/tree/master/insert-time.el
(require 'insert-time)
(define-key global-map [(control c)(d)] 'insert-date-time)
(define-key global-map [(control c)(control v)(d)] 'insert-personal-time-stamp)
M-1 M-! 데이트
이로 인해 실행하는 쉘 명령이 새 버퍼가 아닌 현재 편집중인 버퍼에 삽입됩니다.
감사합니다, CMS! 가치있는 것에 대한 나의 변형은 나를 충분히 행복하게합니다.
(defvar bjk-timestamp-format "%Y-%m-%d %H:%M"
"Format of date to insert with `bjk-timestamp' function
%Y-%m-%d %H:%M will produce something of the form YYYY-MM-DD HH:MM
Do C-h f on `format-time-string' for more info")
(defun bjk-timestamp ()
"Insert a timestamp at the current point.
Note no attempt to go to beginning of line and no added carriage return.
Uses `bjk-timestamp-format' for formatting the date/time."
(interactive)
(insert (format-time-string bjk-timestamp-format (current-time)))
)
다음을 사용하여 .emacs가 호출하는 파일에 이것을 넣습니다.
(load "c:/bjk/elisp/bjk-timestamp.el")
두 가지 모두 내 .emacs에서 다른 것을 깨뜨리지 않고 쉽게 수정할 수있게 해주 며 언젠가이 Emacs Lisp 프로그래밍이 무엇인지 실제로 배우는 쉬운 진입 점을 만들 수있었습니다.
내 n00b 기술에 대한 PS 비평은 가장 환영합니다.
For an answer similar to ones already posted, along with explanations and more extensions such as automatically opening a file and inserting the current date at the end of it (like a journal), check out Paul Ford's discussion of his emacs utilities.
Here's my take on it.
(defun modi/insert-time-stamp (option)
"Insert date, time, user name - DWIM.
If the point is NOT in a comment/string, the time stamp is inserted prefixed
with `comment-start' characters.
If the point is IN a comment/string, the time stamp is inserted without the
`comment-start' characters. If the time stamp is not being inserted immediately
after the `comment-start' characters (followed by optional space),
the time stamp is inserted with “--” prefix.
If the buffer is in a major mode where `comment-start' var is nil, no prefix is
added regardless.
Additional control:
C-u -> Only `comment-start'/`--' prefixes are NOT inserted
C-u C-u -> Only user name is NOT inserted
C-u C-u C-u -> Both prefix and user name are not inserted."
(interactive "P")
(let ((current-date-time-format "%a %b %d %H:%M:%S %Z %Y"))
;; Insert a space if there is no space to the left of the current point
;; and it's not at the beginning of a line
(when (and (not (looking-back "^ *"))
(not (looking-back " ")))
(insert " "))
;; Insert prefix only if `comment-start' is defined for the major mode
(when (stringp comment-start)
(if (or (nth 3 (syntax-ppss)) ; string
(nth 4 (syntax-ppss))) ; comment
;; If the point is already in a comment/string
(progn
;; If the point is not immediately after `comment-start' chars
;; (followed by optional space)
(when (and (not (or (equal option '(4)) ; C-u or C-u C-u C-u
(equal option '(64))))
(not (looking-back (concat comment-start " *")))
(not (looking-back "^ *")))
(insert "--")))
;; If the point is NOT in a comment
(progn
(when (not (or (equal option '(4)) ; C-u or C-u C-u C-u
(equal option '(64))))
(insert comment-start)))))
;; Insert a space if there is no space to the left of the current point
;; and it's not at the beginning of a line
(when (and (not (looking-back "^ *"))
(not (looking-back " ")))
(insert " "))
(insert (format-time-string current-date-time-format (current-time)))
(when (not (equal option '(16))) ; C-u C-u
(insert (concat " - " (getenv "USER"))))
;; Insert a space after the time stamp if not at the end of the line
(when (not (looking-at " *$"))
(insert " "))))
I prefer to bind this to C-c d
.
'IT TIP' 카테고리의 다른 글
버튼 그룹의 너비를 100 %로 설정하고 버튼의 너비를 같게 만드시겠습니까? (0) | 2020.11.02 |
---|---|
복잡한 C 선언 (0) | 2020.11.02 |
UIScrollView 콘텐츠의 보이는 사각형 가져 오기 (0) | 2020.11.02 |
프로젝트로드 오류 : 3 개의 패싯 세부 사항을로드 할 수 없습니다. (0) | 2020.11.02 |
Angular 2 및 TypeScript로 두 개의 객체 배열을 병합 하시겠습니까? (0) | 2020.11.02 |