2008-10-30 20 views
58

Emacs में कौन से आदेश वर्तमान दिनांक और समय फ़ाइल के टेक्स्ट बफर में सम्मिलित करने के लिए उपयोग कर सकते हैं?मैं Emacs का उपयोग कर फ़ाइल में वर्तमान दिनांक और समय कैसे डाल सकता हूं?

अपने .emacs फ़ाइल में (उदाहरण के लिए, नोटपैड में बराबर बस F5 नोटपैड के लिए ही उपयोगी सुविधा के बारे में है जो दबाने है!)

+2

नोटपैड में Ctrl + G "गोटो लाइन" संवाद खोलता है, यह भी उपयोगी है! – cfeduke

उत्तर

110
C-u M-! date 
+17

कितना अविश्वसनीय सहज ज्ञान युक्त :) – msandiford

+50

बस पूर्णता के लिए: 'एम-!' फ़ंक्शन 'shell-command' के लिए कुंजीपटल शॉर्टकट है। तो 'एम-! डेट' शेल कमांड 'डेट' को कॉल करेगा, और आउटपुट एरिया में दिखाएगा (मिनीबफर, क्योंकि आउटपुट फिट करने के लिए पर्याप्त छोटा है)। 'सी-यू 'एक उपसर्ग तर्क है जो' एम-! 'को इसके आउटपुट को वर्तमान बफर में रखता है। – ShreevatsaR

+10

यदि आप विंडोज़ का उपयोग करते हैं, तो "डेट" सिस्टम दिनांक बदलने के लिए कमांड होने पर आपको इसके साथ आश्चर्यजनक परिणाम मिलेंगे। एलिसिप के साथ इस प्रश्न को संभालने वाले उत्तरों यूनिक्स, यूनिक्स-जैसी या यहां तक ​​कि लिनक्स ऑपरेटिंग सिस्टम पर निर्भर नहीं हैं। –

32

रख:

;; ==================== 
;; 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) 

Reference

+1

मैं इसके लिए कुछ समान उपयोग करता हूं, लेकिन मैं इसे सी-सी सी-टी से सी-एक्स सी-टी में बदलता हूं क्योंकि सी-सी सी-टी ऑर्ग-मोड के "मार्क टूडो आइटम" बाध्यकारी के रास्ते में आता है। जो मेरे लिए मांसपेशी स्मृति में दुर्भाग्य से कड़ी मेहनत है। :) – AssembledGhost

+0

'" सी-सी \ सी-डी "' मेरे लिए कुछ भी नहीं होता है। दरअसल, जब 'सी-डी' टाइप किया जाता है तो यह वर्तमान रेखा को हटा देता है। लेकिन मुझे लगता है कि क्यों 'सी-सी' काम नहीं कर रहा है। – Jack

5

यहां एक पैकेज है जिसे मैंने कुछ समय पहले लिखा था जो आप पूछ रहे हैं।

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) 
13

आप yasnippet, जो आप "समय" और टैब कुंजी टाइप करने देगा, और अधिक के अलावा एक पूरी बहुत कुछ करता है स्थापित कर सकते हैं। यह दृश्यों के पीछे current-time-string पर कॉल करता है, ताकि आप format-time-string का उपयोग करके स्वरूपण को नियंत्रित कर सकें।

+1

यास्निपेट अंतर्निहित टेम्पलेट्स और हिप्पी-विस्तार की तुलना में एक संसाधन हॉग है। –

25

मैं इन छोटे-छोटे स्निपेट का उपयोग किया है:

(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

+0

मीठा, नौकरी अच्छी तरह से करता है :) – ljs

+1

धन्यवाद। बहुत अच्छा। किसी भी व्यक्ति के लिए जो पूरी तरह से emacs पर एक नोब है: इसे अपने '.emacs.' फ़ाइल में जोड़कर इसका उपयोग करें और इसे सेव करें, और फिर प्रत्येक कर्सर के अंत कोष्ठक में अपने कर्सर (बिंदु) को ले जाएं और फिर प्रत्येक के लिए' एमएक्स मी ' । अब आप जहां भी चाहें 'एम-एक्स अब' या 'एम-एक्स आज' का उपयोग कर सम्मिलित कर सकते हैं। – celwell

1

एम -1 एम से आया है! दिनांक

यह उस शेल कमांड का कारण बनता है जिसे आप बफर में डालने के लिए चलाते हैं जिसे आप वर्तमान में एक नए बफर के बजाय संपादित कर रहे हैं।

1

धन्यवाद, सीएमएस! मेरे भिन्नता, क्या यह लायक है के लिए - मुझे काफी खुश करता:

(load "c:/bjk/elisp/bjk-timestamp.el") 

जो दोनों यह आसान संशोधित करने के लिए बनाता है:

(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 द्वारा कहा जाता है में रखते मेरे .emacs में कुछ और तोड़ने के जोखिम के बिना, और मुझे किसी दिन वास्तव में एक आसान प्रविष्टि बिंदु की अनुमति दी, वास्तव में यह सीखना कि यह Emacs Lisp प्रोग्रामिंग क्या है।

पीएस मेरी एन 00 बी तकनीक के बारे में आलोचना सबसे ज्यादा स्वागत है।

1

स्पष्टीकरण और अधिक एक्सटेंशन जैसे कि स्वचालित रूप से फ़ाइल खोलने और इसके अंत में वर्तमान दिनांक (जर्नल की तरह) डालने जैसे अधिक उत्तरों के उत्तर के लिए, Paul Ford's discussion of his emacs utilities देखें।

10

डालने की तारीख के लिए: एम एक्स ऑर्ग-समय स्टाम्प डालने दिनांक समय के लिए: सी-यू एम एक्स ऑर्ग-समय स्टाम्प

हो सकता है आप इस आदेश के लिए एक वैश्विक कुंजी बाध्य कर सकते हैं।

संगठन मोड की विधि बहुत उपयोगकर्ता के अनुकूल है, आप कैलेंडर से किसी भी तारीख का चयन कर सकते हैं।

+0

बिल्कुल वही जो मैं खोज रहा था, धन्यवाद @tangxinfa! मैंने इसे 'एन्टर' के साथ एक मैक्रो में रखा, इसे एक नाम दिया, और इसे कीबाउंड किया। – ragerdl

0

यहां मेरा लेना है।

(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 " ")))) 

मैं इसे C-c d पर बांधना पसंद करता हूं।

संबंधित मुद्दे

 संबंधित मुद्दे