Emacs-Jabber में सुधार

शुरुआत


पहले से ही jabber.el पर एक अवलोकन लेख था - emacs के लिए jabber-client। पिजिन के बाद इस क्लाइंट को आजमाने का फैसला करने के बाद, मुझे इनपुट इतिहास या स्वरूपित संदेशों जैसी परिचित चीजों की कमी हो गई। दुर्भाग्य से, emacs-jabber उतनी तेजी से विकसित नहीं हो रहा है जितना हम चाहते हैं। सौभाग्य से, emacs कॉन्फ़िगरेशन विकल्प लगभग अंतहीन हैं, इसलिए सही जोड़ना आसान है। इस लेख में मैं बताऊंगा कि मैंने इनपुट इतिहास को कैसे लागू किया। यदि यह विषय जनता के लिए रुचि का है, तो भविष्य में मैं प्रारूपित संदेश (html) और कुछ अन्य उपहार भेजने का वर्णन करूंगा।

आरक्षण
वर्णित सब कुछ अपने लिए किया गया था। मैं प्रस्तावना का उपयोग करता हूं, इसलिए कुछ कार्य तीसरे पक्ष के पुस्तकालयों से हो सकते हैं और शुद्ध एमैक्स में मौजूद नहीं हो सकते हैं। मैं केवल चैट का उपयोग करता हूं, सम्मेलनों के लिए निर्दिष्ट कोड को ठीक करने की आवश्यकता होगी।


इनपुट इतिहास


पिजिन में एक बहुत ही आसान चीज इनपुट इतिहास है। Ctrl + up के द्वारा आप भेजे हुए मैसेज के इतिहास के साथ वापस जा सकते हैं, और ctrl + down से आप आगे जा सकते हैं। इस कार्यक्षमता को emacs-jabber में जोड़ें। हमें तीन चर की आवश्यकता होगी: दर्ज किए गए वाक्यांशों की एक सूची, इस सूची में वर्तमान स्थिति और अंतिम पाठ दर्ज किया गया लेकिन अभी तक नहीं भेजा गया है।
(defvar my-jabber-input-history '() "Variable that holds input history") (make-variable-buffer-local 'my-jabber-input-history) (defvar my-jabber-input-history-position 0 "Current position in input history") (make-variable-buffer-local 'my-jabber-input-history-position) (defvar my-jabber-input-history-current nil "Current input value") (make-variable-buffer-local 'my-jabber-input-history-current) 

संदेश भेजते समय, उसे सूची में जोड़ें:
 (defun my-jabber-input-history-hook (body id) (add-to-list 'my-jabber-input-history body t) (setq my-jabber-input-history-position (length my-jabber-input-history))) (add-hook 'jabber-chat-send-hooks 'my-jabber-input-history-hook) 

महत्वपूर्ण: my-jabber-input-history-position कहानी के अंतिम तत्व को इंगित नहीं करता है, लेकिन इसके पीछे (खरोंच से क्रमांकन) है। यह तर्कसंगत है, क्योंकि हम अभी तक सूची में नहीं गए हैं।
सूची के माध्यम से वापस जाने का कार्य:
 (defun my-jabber-previous-input () (interactive) (let (current-input (pos my-jabber-input-history-position) (len (length my-jabber-input-history))) (if (= pos 0) (message "%s" "No previous input") (setq current-input (delete-and-extract-region jabber-point-insert (point-max))) (when (= pos len) ; running first time, save current input (setq my-jabber-input-history-current current-input)) (decf my-jabber-input-history-position) (insert (nth my-jabber-input-history-position my-jabber-input-history))))) 

यह सरल है, केवल ध्यान देने लायक बात वर्तमान में दर्ज किए गए पाठ को सहेजना है। यदि उपयोगकर्ता कहानी का उपयोग करने के बारे में अपना मन बदल देता है, तो हम उसे पुनर्स्थापित कर सकते हैं जो वह दर्ज करने में कामयाब रहा।
सूची में आगे जाने का कार्य:
 (defun my-jabber-next-input () (interactive) (let ((pos my-jabber-input-history-position) (len (length my-jabber-input-history))) (cond ((= pos (1- len)) ; pointing at the last element, insert saved input (incf my-jabber-input-history-position) (delete-region jabber-point-insert (point-max)) (insert my-jabber-input-history-current) (setq my-jabber-input-history-current nil)) ((= pos len) ; pointing beyound last element, notify user (message "%s" "No next input")) (t ; insert next history item (incf my-jabber-input-history-position) (delete-region jabber-point-insert (point-max)) (insert (nth my-jabber-input-history-position my-jabber-input-history)))))) 

यहाँ तर्क पेचीदा है। यदि हम सूची में अंतिम आइटम पर हैं (लेन - 1), तो हमें पहले से सहेजे गए उपयोगकर्ता इनपुट को सम्मिलित करना होगा। लेकिन हम अभी भी स्थिति बढ़ा रहे हैं ताकि अगली बार दूसरी स्थिति काम करे।
हम इन कार्यों को सुविधाजनक बटन संयोजनों पर लटकाते हैं:
 (define-key jabber-chat-mode-map (kbd "Mp") 'my-jabber-previous-input) (define-key jabber-chat-mode-map (kbd "Mn") 'my-jabber-next-input) 

हो गया। अब हमारे पास समान कार्यशीलता है जैसे कि pidgin + में सूचनाओं की शुरुआत और अंत के बारे में + डुप्लिकेट संदेश के बिना इतिहास (ऐड-टू-लिस्ट के लिए धन्यवाद)।
इडो-मोड के प्रेमियों के लिए, यह फ़ंक्शन काम आ सकता है:
 (defun my-jabber-input-history-choose () (interactive) (let ((choice (ido-completing-read "Select history item: " (reverse my-jabber-input-history)))) (delete-region jabber-point-insert (point-max)) (insert choice))) 

चूँकि यह ido है, लिस्ट में सर्च आपके टाइप करने पर भी काम करता है (भले ही फजी-इलस-फ्लेक्स-मैचिंग वैरिएबल सेट हो) और Cs / Cr द्वारा विकल्पों पर ध्यान दिया जाता है।

अंत


टेक्स्ट को एमआर-मोड का उपयोग करके एमएसीएस में तैयार किया जाता है और एक डॉकबुक (सी-सी सीई डी) को निर्यात किया जाता है।

संदर्भ


Lispokod

इस लेख का स्रोत

प्री-बुक एक्सएमएल को हबर-फ्रेंडली प्रारूप में परिवर्तित करने के लिए एक्सएसएलटी।

Source: https://habr.com/ru/post/In164573/


All Articles