ELIM/garak in Emacs configuration - emacs

Does someone know how to setup ELIM in emacs?
There is no information about adding accounts etc.
when I run
/add-account
here comes a message
setq: Symbol's function definition is
void: garak-read-protocol
Thank you

This was fixed in commit d3c2f467ebf606fbe6406b2aac783aa68aa91019, which may not have made it into a release yet. You can try checking out from the git repo, or just monkeypatch in this definition:
(defun garak-read-protocol (proc)
(let ((available (mapcar 'car (elim-protocol-alist proc))))
(completing-read "protocol: " available nil t) ))

Privet, Dmitry!
(Ununtu 9.04, GNU Emacs 23.2.1 (i686-pc-linux-gnu, GTK+ Version 2.16.1) of 2010-06-21 on jonesbook)
Ya ustanovil ego tak:
1) u menia uge bil ustanovlen libpurple + pidgin (ver. 2.5.5, some old)
2) git clone elim source from github into dir ~/.emacs.d/elim and make it. OK. "elim-client" is here
3) Add link in .emacs to dir ~/.emacs.d/elim/elisp, e.g.
(add-to-list 'load-path "~/.emacs.d/elim/elisp")
(load-library "garak")
4) Optional. (emacs must compiled with --dbus). Install todochiku.el and put
(require 'todochiku)
Then, M-x garak
command
/add-account
work without such message: "Symbol definition is void: garak-read-protocol"
See garak.el
(add-account . garak-account-update )
...
(add-account . garak-cmd-add-account )
(defun garak-cmd-add-account (args)
(let (items user proto pass options elim errval)
(setq items (split-string args)
user (car items)
proto (cadr items)
items (cddr items))
(setq elim garak-elim-process)
(when (= (length proto) 0) (setq proto (garak-read-protocol elim)))
(when (= (length user ) 0) (setq user (garak-read-username elim proto)))
(when (and (car items) (not (string-match "=" (car items))))
(setq pass (car items) items (cdr items)))
(when (= (length pass ) 0) (setq pass (garak-read-password elim proto)))
;; options not supported yet:
;;(mapcar
;; (lambda (O) (setq options (nconc options (split-string "=" O)))) items)
;; (message "(elim-add-account PROC %S %S %S %S)" user proto pass nil)
(elim-add-account elim user proto pass options)
(format "/add-account %s" args) ))
(defun garak-account-update (proc name id status args)
"This function handles updating the garak ui when the state of one of your
accounts changes. Typically this is as a result of elim-account-status-changed
elim-connection-state or elim-connection-progress, but any call can be handled as long as an \"account-uid\" entry is present in the ARGS alist."
(let (buffer auid where-widget point end icon-name
icon conn kids node tag proto iname alt atag aname)
(setq buffer (elim-fetch-process-data proc :blist-buffer)
auid (elim-avalue "account-uid" args)
status nil)
;; update any account conversation buffers with _our_ new status
(garak-update-account-conversations proc auid)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; proceed to updating the blist ui buffer
(when (buffer-live-p buffer)
(with-current-buffer buffer
(setq where-widget (garak-ui-find-node auid :account))
;; set the conn or status data (whichever is appropriate)
(cond ((eq name 'elim-account-status-changed) (setq status args))
((eq name 'elim-connection-state ) (setq conn args))
((eq name 'elim-connection-progress ) (setq conn args)))
;; fetch any data we did not receive:
(when (not conn ) (setq conn (elim-account-connection proc auid)))
(when (not status) (setq status (elim-account-status proc auid)))
;; pick the most suitable status icon
(if (eq name 'elim-exit)
(setq icon-name ":offline")
(setq icon-name (garak-account-list-choose-icon conn status)))
;;(message "CHOSE ICON: %S" icon-name)
;; widget not found or removing an account => refresh the parent node.
;; otherwise => update node icon
(if (or (eq 'remove-account name) (not where-widget))
;; refreshing parent node:
(when (setq where-widget (garak-ui-find-node :accounts :garak-type)
point (car where-widget))
(setq node (widget-at point)
kids (garak-tree-widget-apply node :expander))
(garak-tree-widget-set node :args kids)
(when (garak-tree-widget-get node :open)
(widget-apply node :action)
(widget-apply node :action)))
;; updating node icon:
(setq point (car where-widget)
end (next-single-char-property-change point 'display)
tag (elim-avalue icon-name garak-icon-tags)
adata (elim-account-data proc auid)
proto (elim-avalue :proto adata)
aname (elim-avalue :name adata)
iname (format ":%s" proto)
atag (or (elim-avalue iname garak-icon-tags) " ?? ")
alt (format "[%-4s]%s%s" atag tag aname)
icon (tree-widget-find-image icon-name))
(let ((inhibit-read-only t) old)
(setq widget (widget-at point)
old (widget-get widget :tag))
(if (eq (cdr where-widget) 'menu-choice)
(widget-put widget :tag alt)
(widget-put widget :tag tag))
(if (and icon (tree-widget-use-image-p))
(put-text-property point end 'display icon) ;; widgets w images
(when tag
(setq end (+ (length old) point))
(save-excursion
(goto-char point)
(setq old (make-string (length old) ?.))
(when (search-forward-regexp old end t)
(if (eq (cdr where-widget) 'menu-choice)
(replace-match alt nil t)
(replace-match tag nil t))) )) )) )) )))
In these functions there are many calls (setq ...) and i don't know - where to search problem.
Your should give more information about error. Commands stack, for example.

Related

How emacs js2-mode jump to definition open in other window?

In js2-mode, M-. runs the command js2-jump-to-definition, this works great. But I want it go to the definition in other window. I find the code js2-jump-to-definition in Github.
What is the easiest way to make it open in other window?
(defun js2-jump-to-definition (&optional arg)
"Jump to the definition of an object's property, variable or function."
(interactive "P")
(if (eval-when-compile (fboundp 'xref-push-marker-stack))
(xref-push-marker-stack)
(ring-insert find-tag-marker-ring (point-marker)))
(js2-reparse)
(let* ((node (js2-node-at-point))
(parent (js2-node-parent node))
(names (if (js2-prop-get-node-p parent)
(reverse (let ((temp (js2-compute-nested-prop-get parent)))
(cl-loop for n in temp
with result = '()
do (push n result)
until (equal node n)
finally return result)))))
node-init)
(unless (and (js2-name-node-p node)
(not (js2-var-init-node-p parent))
(not (js2-function-node-p parent)))
(error "Node is not a supported jump node"))
(push (or (and names (pop names))
(unless (and (js2-object-prop-node-p parent)
(eq node (js2-object-prop-node-left parent)))
node)) names)
(setq node-init (js2-search-scope node names))
;; todo: display list of results in buffer
;; todo: group found references by buffer
(unless node-init
(switch-to-buffer
(catch 'found
(unless arg
(mapc (lambda (b)
(with-current-buffer b
(when (derived-mode-p 'js2-mode)
(setq node-init (js2-search-scope js2-mode-ast names))
(if node-init
(throw 'found b)))))
(buffer-list)))
nil)))
(setq node-init (if (listp node-init) (car node-init) node-init))
(unless node-init
(pop-tag-mark)
(error "No jump location found"))
(goto-char (js2-node-abs-pos node-init))))

How can I cycle through only those buffers which are in a given major mode (such as Python-mode ) ?

How can I cycle through only those buffers which are in a given major mode (such as Python-mode ) ?
Currently I am using C-X-Left/Right arrows, but these also show all sorts of irrelevant (i.e. non source code) buffers, any idea how can I restrict the buffer switching only to a specific type of buffer (with a given major mode) ?
I could not find something ready-made. However, it is not very hard to make the suitable commands.
(defun buffer-mode-alist ()
"Returns a list of (<buffer-name> . <major-mode>) pairs."
(let ((all-buffers (buffer-list))
(rv nil))
(while all-buffers
(let* ((this (car all-buffers))
(name (buffer-name this)))
(setq all-buffers (cdr all-buffers))
(when name
(setq rv (cons (cons name (with-current-buffer this major-mode)) rv)))))
rv))
(defun buffers-with-major-mode (the-major-mode)
(let ((buffer-alist (buffer-mode-alist))
(rv nil))
(while buffer-alist
(let ((this (car buffer-alist)))
(setq buffer-alist (cdr buffer-alist))
(if (eql (cdr this) the-major-mode)
(setq rv (cons (car this) rv)))))
(sort rv #'string<)))
(defun spin-buffers (buffer-list current)
(cond ((not (member current buffer-list)) buffer-list)
((string= current (car buffer-list)) buffer-list)
(t (spin-buffers (append (cdr buffer-list)
(list (car buffer-list)))
current))))
(defvar next-buffer-mode nil)
(defun choose-next-buffer-mode (mode)
"Ask for what major mode should be used as a selector for next-buffer-with-mode."
(interactive "aMajor Mode: ")
(setq next-buffer-mode mode))
(defun next-buffer-with-mode (set)
"Switches to the 'next' buffer with a given mode. If the mode is not set,
require it to be set, by calling choose-next-buffer-mode. If any prefix
argument is passed, also call choose-next-buffer-mode."
(interactive "P")
(when (or (not next-buffer-mode)
set)
(call-interactively 'choose-next-buffer-mode))
(let ((buffers (spin-buffers (buffers-with-major-mode next-buffer-mode)
(buffer-name))))
(when (cdr buffers)
(switch-to-buffer (cadr buffers)))))
(defun prev-buffer-with-mode (set)
"Switches to the 'previous' buffer with a given mode. If the mode is not set,
require it to be set, by calling choose-next-buffer-mode. If any prefix
argument is passed, also call choose-next-buffer-mode."
(interactive "P")
(when (or (not next-buffer-mode)
set)
(call-interactively 'choose-next-buffer-mode))
(let ((buffers (spin-buffers (buffers-with-major-mode next-buffer-mode)
(buffer-name))))
(when buffers
(switch-to-buffer (car (last buffers))))))

How to view man page using Info in Emacs?

I can view man pages using info in the terminal:
info pthread_create
However, it is not possible with info in Emacs, even with info-apropos or info-menu.
EDIT:
It seems that fall-backs are not in the concept of Info-mode.
There follows a work-around applying advice. It does not work perfect but around the missing feature ;-).
It defines a fall-back for Info-goto-node (in Info-mode bound to g) and for Info-menu (in Info-mode bound to m).
Furthermore, it adds manual-apropos to info-apropos.
(require 'woman)
(defun Info-man-completion (_caller _info string predicate action)
"Add man entries to info completion."
;; prepare woman:
(unless (and woman-expanded-directory-path woman-topic-all-completions)
(setq woman-expanded-directory-path
(woman-expand-directory-path woman-manpath woman-path)
woman-topic-all-completions
(woman-topic-all-completions woman-expanded-directory-path)))
;; do completions:
(cond
((null action) ;; try-completion
;; shortest wins
(let ((_man (try-completion string woman-topic-all-completions)))
(cond
((eq _info t)
t)
((eq _man t)
t)
((and (stringp _info) (stringp _man))
(if (> (length _info) (length _man))
_man
_info))
((stringp _info)
_info)
(t _man)
)))
((eq action t) ;; all-completions
(let ((_man (all-completions string woman-topic-all-completions)))
(append _info _man)
))
((eq action 'lambda) ;; test-completion
(try-completion string _caller))
((eq action 'metadata) ;; state of current completion
'(metadata) ;; no specification
)))
;; args: string predicate code
(defadvice Info-read-node-name-1 (around man activate)
"Add man entries to info completion."
(setq ad-return-value (apply 'Info-man-completion 'Info-read-node-name-1 ad-do-it (ad-get-args 0))))
;;
(defadvice Info-complete-menu-item (around man activate)
"Add man entries to info completion."
(setq ad-return-value (apply 'Info-man-completion 'Info-complete-menu-item ad-do-it (ad-get-args 0))))
(defadvice Info-goto-node (around man activate)
"If no info node is found for string lookup and show man entry."
(condition-case err
ad-do-it
(user-error
(let ((err-str (car-safe (cdr err))))
(if (and (stringp err-str)
(string-match "No such node or anchor:" err-str))
(man (ad-get-arg 0))
(signal 'user-error err-str)
)))))
(defadvice Info-menu (around man activate)
"If no info menu entry is found for string lookup and show man entry."
(condition-case err
ad-do-it
(user-error
(let ((err-str (car-safe (cdr err))))
(if (and (stringp err-str)
(string-match "No such item in menu" err-str))
(man (ad-get-arg 0))
(signal 'user-error err-str)
)))))
(defadvice Info-apropos-find-node (after man activate)
"Add man appropos to info appropos."
(let (item)
(goto-char (point-max))
(let ((inhibit-read-only t))
(insert "\nMatches found by man-apropos\n\n")
(let ((beg (point))
(nodeinfo (assoc nodename Info-apropos-nodes)))
(if nodeinfo
(let ((search-string (nth 1 nodeinfo)))
(call-process "apropos" nil t t search-string)
(goto-char beg)
(while (re-search-forward "^\\(\\(?:[[:alnum:]]\\|\\s_\\)+\\)\\(?:[[:blank:]]+\\[\\]\\)?\\([[:blank:]]+([[:alnum:]]+)\\)[[:blank:]]+-[[:blank:]]+\\(.*\\)$" nil t)
(replace-match (replace-regexp-in-string "\\\\" "\\\\\\\\" (format "* %-38s.%s"
(format "%s:" (match-string 1))
(concat (match-string 1) (match-string 2))
(match-string 3))))))
(man nodename)
)))))
Info gives an error that the node is not available. Thereafter, the manual page is shown if there is one.
[Edited]
EmacsWiki says that iman:
Opens either an info format manual with InfoMode or a man page with
ManMode.
It links to the author's website:
http://homepage1.nifty.com/bmonkey/emacs/elisp/iman.el
Found M-x woman MANPAGE RET to most convenient way to call manpages from inside Emacs.

Shortcut for inserting environments in `org-mode`

I'm using org-mode for organizing myself (very useful so far!). However, it is kind of annoying writting
#+begin_comment
...
#+end_comment
each time I'd like to insert an environment.
Question
Is there a shortcut to insert the #+begin_ and #+end_ for a given environment?
In the same way C-c C-o comment RET would insert
\begin{comment}
\end{comment}
in latex-mode.
Org has a facility called "Easy templates": http://orgmode.org/manual/Easy-Templates.html
A template for comment is missing but you can add it with:
(add-to-list 'org-structure-template-alist '("C" "#+begin_comment\n?\n#+end_comment"))
And use it by typing <C followed by TAB.
Alternatively, you could use yasnippet.
Now the corresponding template section is called Structure Template and the insertion sequence is invoked by C-c C-,. I didn't (require 'org-tempo) which is described to support insertion keys like <s TAB.
The comment environment is already defined in org-structure-template-alist. So the comment would be inserted by
C-c C-, C
It's still possible to add a user defined sequence by, for example,
C-c C-, [TAB|RET|SPC] src python :results output :session
delivering
#+begin_src python :results output :session
#+end_src
(emacs 25.2.2, org-mode 9.2)
You could have a look at "org-auctex-keys.el", a minor mode which I created to offer AUCTeX key bindings within Org documents.
In this case, you'd use C-c C-e to insert an environment (prompt to enter the environment name), as what AUCTeX does.
If you're interested, check it out at https://github.com/fniessen/org-auctex-key-bindings.
Not as elegant as the answer of Michael Markert but maybe more expandable.
1) You can select a region and put the block around it or you can just put the block at point.
2) Keyword expansion and history.
3) Keystrokes: C-c b
The command could be further expanded. E.g., for the src block the various switches like -n -r and export to files could be supported.
(defun list-major-modes ()
"Returns list of potential major mode names (without the final -mode).
Note, that this is guess work."
(interactive)
(let (l)
(mapatoms #'(lambda (f) (and
(commandp f)
(string-match "-mode$" (symbol-name f))
;; auto-loaded
(or (and (autoloadp (symbol-function f))
(let ((doc (documentation f)))
(when doc
(and
(let ((docSplit (help-split-fundoc doc f)))
(and docSplit ;; car is argument list
(null (cdr (read (car docSplit)))))) ;; major mode starters have no arguments
(if (string-match "[mM]inor" doc) ;; If the doc contains "minor"...
(string-match "[mM]ajor" doc) ;; it should also contain "major".
t) ;; else we cannot decide therefrom
))))
(null (help-function-arglist f)))
(setq l (cons (substring (symbol-name f) 0 -5) l)))))
(when (called-interactively-p 'any)
(with-current-buffer (get-buffer-create "*Major Modes*")
(clear-buffer-delete)
(let ((standard-output (current-buffer)))
(display-completion-list l)
(display-buffer (current-buffer)))))
l))
(defvar org-insert-block-hist nil
"History for command `org-insert-block'")
(defvar org-insert-block-hist/src:major nil
"History for major mode in org src blocks.")
(defvar org-insert-block-list (append org-protecting-blocks
'("comment" ""))
"List of block types offered as completion for command `org-insert-block'")
;; block_src switches: -n () -r (references) -l "((%s))" (label format) -k (keep labels)
(defvar org-insert-block-list-specials
"Assoc list of Commands for reading additional specification of org-blocks.")
(setq org-insert-block-list-specials
'(("src" . (concat " " (completing-read "Major mode:"
(list-major-modes)
nil nil
(car org-insert-block-hist/src:major)
'(org-insert-block-hist/src:major . 1)
)))))
(defun org-insert-block (bl &optional b e attributes)
"Put region between b and e into org-block of kind bl.
If b or e is nil then put org-block limiters around point.
The string attributes is inserted behind the string #+begin_... "
(interactive
(let ((usereg (use-region-p))
(blKind (completing-read "Input block kind (tab: completion, uparrow: history):"
org-insert-block-list nil nil (car org-insert-block-hist) '(org-insert-block-hist . 1))))
(list
blKind
(when usereg (region-beginning))
(when usereg (region-end))
(let ((spec (assoc blKind org-insert-block-list-specials)))
(when spec (eval (cdr spec)))
))))
(let ((begBlock (concat "\n#+begin_" bl attributes "\n"))
(endBlock (concat "\n#+end_" bl "\n")))
(if (and b e)
(save-restriction
(narrow-to-region b e)
(goto-char (point-min))
(insert begBlock)
(goto-char (point-max))
(insert endBlock)
(indent-region (point-min) (point-max)))
(let ((p (point)))
(insert endBlock)
(goto-char p)
(insert begBlock))
)))
(add-hook 'org-mode-hook '(lambda ()
(local-set-key (kbd "C-c b") 'org-insert-block)))

In emacs, can I set up the *Messages* buffer so that it tails?

Basically I want the *Messages* buffer to always scroll to the bottom when a new message arrives.
Can I do that?
I found auto-revert-tail-mode but that works for buffers that are visiting files.
When I tried it in the Messages buffer, it popped an error:
auto-revert-tail-mode: This buffer is not visiting a file
For multiple frames you probably want:
(defadvice message (after message-tail activate)
"goto point max after a message"
(with-current-buffer "*Messages*"
(goto-char (point-max))
(walk-windows (lambda (window)
(if (string-equal (buffer-name (window-buffer window)) "*Messages*")
(set-window-point window (point-max))))
nil
t)))
Just put point at the end of the buffer M->. If you don't manually move it it will stay there -- IOW, you will always see the tail.
This code seems a bit overkill, but a the simple (goto-char (point-max)) wasn't working for me:
(defadvice message (after message-tail activate)
"goto point max after a message"
(with-current-buffer "*Messages*"
(goto-char (point-max))
(let ((windows (get-buffer-window-list (current-buffer) nil t)))
(while windows
(set-window-point (car windows) (point-max))
(setq windows (cdr windows))))))
Here's an implementation that uses the new advice style.
(defun message-buffer-goto-end-of-buffer (&rest args)
(let* ((win (get-buffer-window "*Messages*"))
(buf (and win (window-buffer win))))
(and win (not (equal (current-buffer) buf))
(set-window-point
win (with-current-buffer buf (point-max))))))
(advice-add 'message :after 'message-buffer-goto-end-of-buffer)
i run 23.3 and there were still way too many occasions where the built-in 'solution' and the orginal defadvice on the message function just didn't cut it, so i wrapped that code in a list / toggle / timer set up and it's working beautifully - no more frustration when debugging!
it's generic, so works on any buffer, although i only really use it for..
(toggle-buffer-tail "*Messages*" "on")
..hope it's useful to someone.
;alist of 'buffer-name / timer' items
(defvar buffer-tail-alist nil)
(defun buffer-tail (name)
"follow buffer tails"
(cond ((or (equal (buffer-name (current-buffer)) name)
(string-match "^ \\*Minibuf.*?\\*$" (buffer-name (current-buffer)))))
((get-buffer name)
(with-current-buffer (get-buffer name)
(goto-char (point-max))
(let ((windows (get-buffer-window-list (current-buffer) nil t)))
(while windows (set-window-point (car windows) (point-max))
(with-selected-window (car windows) (recenter -3)) (setq windows (cdr windows))))))))
(defun toggle-buffer-tail (name &optional force)
"toggle tailing of buffer NAME. when called non-interactively, a FORCE arg of 'on' or 'off' can be used to to ensure a given state for buffer NAME"
(interactive (list (cond ((if name name) (read-from-minibuffer
(concat "buffer name to tail"
(if buffer-tail-alist (concat " (" (caar buffer-tail-alist) ")") "") ": ")
(if buffer-tail-alist (caar buffer-tail-alist)) nil nil
(mapcar '(lambda (x) (car x)) buffer-tail-alist)
(if buffer-tail-alist (caar buffer-tail-alist)))) nil)))
(let ((toggle (cond (force force) ((assoc name buffer-tail-alist) "off") (t "on")) ))
(if (not (or (equal toggle "on") (equal toggle "off")))
(error "invalid 'force' arg. required 'on'/'off'")
(progn
(while (assoc name buffer-tail-alist)
(cancel-timer (cdr (assoc name buffer-tail-alist)))
(setq buffer-tail-alist (remove* name buffer-tail-alist :key 'car :test 'equal)))
(if (equal toggle "on")
(add-to-list 'buffer-tail-alist (cons name (run-at-time t 1 'buffer-tail name))))
(message "toggled 'tail buffer' for '%s' %s" name toggle)))))
edit: changed functionality to display tail at the bottom of the window
Here's an amendment over Peter's / Trey's solutions
(defun modi/messages-auto-tail (&rest _)
"Make *Messages* buffer auto-scroll to the end after each message."
(let* ((buf-name "*Messages*")
;; Create *Messages* buffer if it does not exist
(buf (get-buffer-create buf-name)))
;; Activate this advice only if the point is _not_ in the *Messages* buffer
;; to begin with. This condition is required; otherwise you will not be
;; able to use `isearch' and other stuff within the *Messages* buffer as
;; the point will keep moving to the end of buffer :P
(when (not (string= buf-name (buffer-name)))
;; Go to the end of buffer in all *Messages* buffer windows that are
;; *live* (`get-buffer-window-list' returns a list of only live windows).
(dolist (win (get-buffer-window-list buf-name nil :all-frames))
(with-selected-window win
(goto-char (point-max))))
;; Go to the end of the *Messages* buffer even if it is not in one of
;; the live windows.
(with-current-buffer buf
(goto-char (point-max))))))
(advice-add 'message :after #'modi/messages-auto-tail)