elisp

Elisp get function arity?

梦想与她 提交于 2019-12-23 18:02:37
问题 I'd like to be able to do: (function-arity (intern "expt")) I googled up this solution https://github.com/emacsmirror/parser/blob/master/parser-fn.el But it's using help-function-arglist , so it's not exactly straightforward. I'd like something more solid, preferably rock-solid. 回答1: There's no such thing as a rock-solid function-arity . In most cases where people want it, what they really want is to call a function in different ways depending on how many arguments it accepts (because its

refiling to a given subtree by a keybinding

笑着哭i 提交于 2019-12-23 17:31:31
问题 The problem is probably very simple, but I'm struggling because I am new to ELISP. I want to have a keybinding to refile current subtree to subtree TRASH. I have written the code, which doesn't work, though. Could you please help me to fix it? Thanks in advance! The code: (defun org-move-to-trash() (org-refile "TRASH") ;; the function fails here because the parameter has to be specified in a different way. But how? ) (global-set-key (kbd "C-c b") 'org-move-to-trash) 回答1: If you're interested

Can I put condition in emacs lisp macro?

依然范特西╮ 提交于 2019-12-23 16:27:07
问题 How to achieve something like this? (defmacro mood (x) (if (equal (symbol-name x) "t") `(defun happy () (message "Happy")) `(defun sad () (message "Sad"))) ) My aim is to create different function base on argument. Is there any problem doing so? 回答1: Edit 2: You're right -- for cases in which the code being evaluated at expansion-time is entirely dependent on the values of the (unevaluated) macro arguments, I believe it is safe for the macro's returned form to be generated conditionally,

How to set a part of arguments from a list in Emacs Lisp?

自闭症网瘾萝莉.ら 提交于 2019-12-23 14:48:22
问题 I want to set PROGRAM-ARGS of start-process from a list. Like, (start-process process-name "*foobar*" process-path (append some-args (list (concat "the" "other" "arg")))) But this makes error that "... is not string", because start-process accepts only string arguments. How can I solve this? 回答1: You want either apply or sometimes funcall . In this particular case I would go with apply but you need to be familiar with them both. (apply #'start-process process-name "*foobar*" process-path some

How can I cons a list of pairs on to auto-mode-alist?

最后都变了- 提交于 2019-12-23 13:08:44
问题 I have a long list of files and file extensions which I would like to have Emacs open automatically in ruby-mode. From using Google, the most basic solution that works is this: (setq auto-mode-alist (cons '("\.rake$" . ruby-mode) auto-mode-alist)) (setq auto-mode-alist (cons '("\.thor$" . ruby-mode) auto-mode-alist)) (setq auto-mode-alist (cons '("Gemfile$" . ruby-mode) auto-mode-alist)) (setq auto-mode-alist (cons '("Rakefile$" . ruby-mode) auto-mode-alist)) (setq auto-mode-alist (cons '(

Listing all top level global variables in emacs

旧时模样 提交于 2019-12-23 12:33:58
问题 Mostly for my own edification I'm trying to list all of the global variables loaded in the current Emacs session. What I was thinking about doing is producing an HTML file with all of the functions listed. Of course, what would also be useful is the file where the function, var, etc was defined. Is there anything already built into emacs to help? L- 回答1: Something along these lines should do: (let ((result '())) (mapatoms (lambda (x) (when (boundp x) (let ((file (ignore-errors (find-lisp

Why is my term-mode-hook not selecting line mode?

ⅰ亾dé卋堺 提交于 2019-12-23 12:28:47
问题 I wrote this elisp function: (defun run (command) "Open a terminal running a command." (interactive "sCommand: ") (if (buffer-exists (concat "*" command "*" )) (kill-buffer (concat "*" command "*"))) (let ((term-mode-hook (cons (lambda () (term-line-mode)) term-mode-hook))) (ansi-term (cons "sh" (cons "-i" (list "-c" command))) command))) This works nicely except that the new ansi-term buffers remains in char mode (which is the default), so as far as I can tell the term-line-mode call is not

Emacs function to open file [current date].tex

自作多情 提交于 2019-12-23 12:24:30
问题 I'm trying to write an emacs function that uses the current date to create a file. I'm new to emacs and so I'm having trouble with variables and syntax. Here's what I have: (defun daily () (interactive) (let daily-name (format-time-string "%T")) (find-file (daily-name))) I don't understand how emacs uses variables well enough to get it to set the time string as a variable and feed that variable into the find-file function. Any help is appreciated. 回答1: To build on what others are saying:

Emacs-Lisp: How to package emacs-lisp program as PC application?

随声附和 提交于 2019-12-23 12:07:58
问题 Just wondering if it's possible to package and deploy emacs and Lisp program as PC application such that once downloaded, running setup.exe (kind of), then the user can start application to make emacs run the specific Lisp program as if the application were implemented by other languages and platform, such as .Net, or Python. With this approach, it would be easier for ordinary users to use the functionality of the Lisp program rather than become a user of emacs, which often takes some

How to make Emacs use tabs instead of spaces?

你说的曾经没有我的故事 提交于 2019-12-23 09:35:30
问题 I've binded a indent-for-tab-command command to one the keys and I want it to make smart mode-specific indentation just like it already does but with tabs. In all the modes. It always inserts spaces instead of tabs. How to reconfigure/reprogram it? I want to use Emacs as fully customizable editor as it's announced to be. So that it would behave exactly as I want. I do not care about developers' opinions at all and want to customize everything. Is this wrong? 回答1: Not all major modes handle