FAQ Database Discussion Community


I am confused about how to use a variable in elisp

emacs,elisp,quote
I try to set the font as below: (let ((my:font "WenQuanYi Micro Hei Mono")) (when (member my:font (font-family-list)) (set-face-attribute 'default nil :font my:font :width 'condensed) (add-to-list 'default-frame-alist '(font . my:font)))) The set-face-attribute works fine. I can see the font is set to WenQuanYi. But when I check the value of...

how to change the value of sp-navigate-reindent-after-up in smartparens

emacs,lisp,elisp,parentheses
I want to change the default behavior of smartparens to remove the whitespace before the close delimiter. I mean, when I type ) after (a b c |, I hope the final result is (a b c)|. Here, the | is cursor. I searched the documentation of smartparens, and find...

Tramp mode - file open does not work

emacs,elisp,tramp
i try to access remote computer via ssh-tramp mode in emacs using this blog, http://swizec.com/blog/cool-thing-thursday-emacs-tramp-mode/swizec/5646 Command recipe given: C-x C-f // username@ hostname password but, after i press C-x C-f // \n username@, it creates a new file as username@ in the current dir. What am i missing to activate...

Emacs, how to get directory of current buffer?

emacs,elisp
In emacs there is buffer-file-name that gives the full path to a file. But is there a way to get only the directory of the file loaded in the current buffer?

Apply vs funcall symbols in elisp

emacs,elisp
(setq func 'concat) (apply func "a" "b") throws error, ***Eval error*** Wrong type argument: listp, "b" Why does n't apply take all arguments from third position as arguments meant for 'func'?...

Result value of elisp code stored in a file?

emacs,elisp,emacs24,dot-emacs
Looking for a way how evaluate elisp code stored in an external file and pass its result as a function argument. Example demonstrating what I'd like to achieve follows: ;; content of my_template.el '(this is a list) ;; content of .emacs where result of my_template.el has to be used (define-auto-insert...

How to add vertical alignment feature to a major-mode for Emacs

emacs,elisp,vertical-alignment,system-verilog
I am using verilg-mode for emacs everyday but the code alignment is not that good for me. So want to add something like vertical alignment. First, I hope to align the declaration lines like these: bit [1:0] a; bit [3254:0] b; bit unsigned [P_DWIDTH-1:0] c; bit unsigned [P_DWIDTH-1:P_DWIDTH-4] d; int...

Complex/imaginary numbers in elisp?

elisp
Does elisp support imaginary numbers is any way? I'm trying to follow an online math course with lisp interaction mode buffer running. Are there "higher math" modules/libraries for Emacs elisp?

match-* functions not behaving?

emacs,elisp
I'm trying to write a elisp function that marks a Python test function as green or red depending on the input. The arguments are pretty self-explanatory. The navigation part works, but the put-text-property part simply does nothing. I've tried eval-ing the match-* functions, but I cannot make sense of the...

Modify list and return it inside a function in lisp

lisp,elisp,common-lisp
(defun testthis (node index newvalue) (set-nth node index newvalue) node ) I would like to modify the nth element of a list in a function and then returns this list to save the modification performed. How can I do a such function in lisp?...

Let block in elisp with no variable assignments

emacs,elisp
Why does a let form in elisp contain body with no varlist args. Sample code, (defun keyboard-quit () ............... (let (select-active-regions) (deactivate-mark)) ......... ) Does this snippet do the same thing, (defun keyboard-quit () ....................... (select-active-regions) (deactivate-mark) ................................... ) This code snippet is taken from simple.el for Ctrl + G...

Does anyone know if it is possible to return nothing in console for elisp after a function ends?

emacs,lisp,elisp,return-value
Right now whenever I try to not return anything, I get nil or t. The last spot of my function ends in an if statement that has nothing in the body. So like this: (if (counter<ten) () (...)) ...

isearch `interactive` spec uses special characters for user input

emacs,elisp
(defun isearch-forward (&optional regexp-p no-recursive-edit) (interactive "P\np") (isearch-mode t (not (null regexp-p)) nil (not no-recursive-edit))) what does special characters p(small lettered p) do as args to interactive function? does the first character P (in caps) mean that regexp-p value comes from a global var definition. Again, coming to arguments, user...

Emacs hotkey for diffing buffer from file without reading (confirming) buffer name

emacs,elisp
I have made a hotkey that calls the diff-buffer-with-file command but then you have to hit enter to confirm that the file you are on is the one to correctly diff: (global-set-key (kbd "C-c e") 'diff-buffer-with-file). I looked up the documentation and saw that you also give &optional BUFFER, so...

Get element from list of list in lisp

lisp,elisp,common-lisp
I am a beginner with lisp. I manipulate list of list: ((name1, second) (name2, second2)) The goal of my function is to get the second element of the list that have name as it first node. For example: my list is: ((name1, second1) (name2, second2)) getelement list name1 should return...

How to define a function with a variable number of arguments?

emacs,elisp
Instead of this: ((lambda (a b) (apply '+ (list a b))) 1 2) it is possible to write this in Scheme: ((lambda args (apply '+ args)) 1 2) Now it is possible to pass more than two arguments to the function. When I try it in Emacs Lisp I get...

Run a command after every input to minibuffer

emacs,elisp
I want to set up a sort of ISearch mode replacement in Emacs, where I can run a command after every input to the minibuffer. Is it possible? EDIT 1: The idea is to completely replace ISearch with my own mode. Ideally, I'd like it to have most of the...

Elisp: how to make this function short

emacs,macros,elisp
I am implementing an plugin, which a lot of project types are remembered. For example: angular, meteor, ember, rails ... And keyed arguments are used. The function creates an hash table with provided keys and values, and assign the hash table to another hash table. Code below: (defun jst-remember-project-type (type...

How to write regexp to match the longest candidate in elisp?

regex,emacs,elisp
I am trying to write a function to remove suffix from a string. The suffix is listed below: agent_pkg agent pkg driver abs_if abs_if_pkg if_pkg if Test string: test_blah_agent_pkg test_blah_agent test_blah_pkg test_blah_driver test_blah_abs_if test_blah_abs_if_pkg test_blah_if_pkg test_blah_if From the above test string, I expect to get test_blah from it. I wrote...

Emacs list of parent modes

emacs,elisp,mode
In emacs is it possible to get a list of parent modes for a derived mode? I found derived-mode-p, but this only allows me to test if a mode is derived from another. ...

How to pipe output from one external process into another?

emacs,elisp
I’ve written a function which takes the contents of the selected region and then runs it through two external processes. Effectively the behaviour I want to replicate is M-| smartypants -2 | ascii2uni -a D -q. The following function works, but requires two calls to call-process-region and temporarily storing the...

How to get Emacs to sort lines by length?

sorting,emacs,elisp
I'd like to be able to highlight a region in Emacs and then sort the region by line length. The closest I've found is the following code which I think will sort by length: (sort-subr t #'forward-line #'end-of-line nil nil (lambda (l1 l2) (apply #'< (mapcar (lambda (range) (- (cdr...

Emacs custom syntactic analysis

emacs,elisp
In emacs, the syntactic analysis is surprisingly little. For example, if I wish to indent parameter names differently than the types in a function declaration, like so: void myfunction( int test ); int is considered an arglist-intro, and test is considered as arglist-cont. However, if I add any more parameters,...

package-install doesn't load the package's files

emacs,elisp
M-x package-install projectile Projectile got installed successfully in ~/.emacs.d/elpa/projectile-20150201.1134/*.el then added (projectile-global-mode) to .emacs, but on restarting emacs, it cries foul as, Symbol's function definition is void: projectile-global-mode I can add projectile installed folder to load-path, but why doesn't emacs load its melpa installed packages automatically?...

Italicise word in emacs

emacs,elisp
I am slightly new to emacs. I am editing a document in latex and I have words that I would like to put in italics. I would like a simple macro where if I place a cursor on the word, and hit a key combination the word is sorrounded with...

Parsing XML with emacs elisp and finding a nested attribute

xml,parsing,emacs,lisp,elisp
Since two days I am working on the following problem: I have some xml wich looks like this: <grammar> <l> <f form="paradāra"><s stem=""/><m meaning="anothers wife; adultery"/></f> <f form="abhimarśeṣu"><s stem="" meaning=""/><m meaning=""/></f> <f form="pravṛttān"><s stem="" meaning=""/><m meaning=""/></f> <f form="mahipatis"><s stem="" meaning=""/><m meaning=""/></f> </l> <l> <f form="udvejana"><s...

Configure ignore dirs on helm-locate

emacs,elisp,helm
M-x helm-locate lists files in hidden folders, that i will never open. How to instruct helm not to look into certain directories for file search & open....

How to fork, make significant changes, and give proper credit? [closed]

licensing,elisp,fork
There is an elisp project on github I have forked. Some of the source files and functions I don't want to change, some I want to change drastically, and others only slightly. The original copyright at the top of each source file mentions the project that it came from. 1)...

emacs: Symbol's function definition is void: loop

emacs,elisp,emacs-prelude
I am testing on loading packages in emacs init.el (Emacs 24.3). I followed a blog by the author of emacs prelude to automatically load packages, and copied the code there into my init.el as in the bottom. However, I got an error message about the loop function/symbol, which says: Symbol's...

The lisp that convert string and grep in emacs?

emacs,elisp,find-grep
I have a file formatted as abc|<hoge> a|<foo> b|<foo> c|<foo> family|<bar> guy|<bar> a|<foo> comedy|<bar> show|<foo> action|<hoge> and want to search search strings by raw (Like "a comedy show" instead of a|<foo> comedy|<bar> show|<foo>) on emacs. I believe using grep on lisp would be the easiest answer but I have not...

Create an Emacs semi-interactive macro

emacs,elisp,emacs23
I would like to create a quick Emacs macro (with C-x () which takes some user input from the minibuffer each time it's executed. The usage scenario is this: You have a complex text to change where the regexp query substitution just doesn't cut it, and you want to create...

word-wrap — using `'cursor t` when overlay 'after-string at end of visual line

emacs,elisp,overlay
PROBLEM:  When point is at the end of a visually wrapped line (but not at the very end of the line), the cursor does not respect the cursor t setting of the overlay after-string -- i.e., the cursor appears at the beginning of the next visually wrapped line, instead of...

emacs call-interactively and key simulation

emacs,elisp
I want to write a small function that saves the cursor's current position, mark the whole buffer, indents it and then goes back to the previous cursor position. I understand there might be easier way to achieve the same result but I'd like to understand how these principles work in...

Putting a :map property on an image

image,emacs,elisp
I'm trying to insert an image in emacs like this: (defun image-wipe-and-insert () (interactive) (let () (with-current-buffer (get-buffer-create "*an image area test buffer*") (switch-to-buffer (current-buffer)) (erase-buffer) (insert-image (find-image '((:type png :file "/usr/share/emacs/24.4/etc/images/icons/hicolor/128x128/apps/emacs.png" :map '((rect . ((0 . 0) . (50 . 50))) anAreaID (:pointer hourglass :help-echo "You found an area!"))...

How can I evaluate something in Emacs init.el file?

emacs,elisp,emacs24
Every time I open .clj file, I have to run M-x cider-jack-in to enable Clojure auto-completion in code file. Can I make Emacs automatically run the command when it starts?...

How do EMACS Lisp programmers read text files for non-editing purposes?

file-io,emacs,elisp
What do EMACS Lisp programmers do, when they want to write something roughly the equivalent of... for line in open("foo.txt", "r", encoding="utf-8").readlines(): ...(split on ws and call a fn, or whatever)... ..? When I look in the EMACS lisp help, I see functions about opening files into text editing buffers...

elisp: defmacro with lambda

emacs,elisp
Sorry, I tried few times and I can't build simple defmacro - can anybody help me with that: So, I want define macro which will expand to: (define-key keymap "*" (lambda () (interactive) (some-func "*"))) I tried something like: (defmacro wrap-and-define-key (keymap key func) `(define-key ,keymap ,key (lambda () (interactive)...

Confused when setting an Emacs face

emacs,elisp
(set-face-attribute 'diredp-dir-heading nil '(t (:foreground blue :background dark1))) What should be the right statements to set this face? Bow//...

Avoid font-locking interfering inside of comments

emacs,elisp,syntax-highlighting,font-lock,major-mode
In my font-lock-defaults I have: ("\\(^\\| \\|\t\\)\\(![^\n]+\\)\n" 2 'factor-font-lock-comment) The comment character is ! and this makes it so comments get the right face. This works mostly, except when there is a competing font-locked entity inside the comment, like a string (delimited by double quotes): ! this line is font-locked...

Implementing streams with elisp

emacs,elisp,sicp
I'm reading section 3.5 of the SICP book, and I'm trying to implement streams using Elisp. The book implements streams using the Scheme language as follows: The core structure of a stream is a pair whose car is the current value of the sequence and its cdr is the promise...

How tool-bar button in emacs works? [duplicate]

emacs,elisp,emacs24,dot-emacs
This question already has an answer here: How to add a tool-bar button in emacs? 2 answers i have a problem to add a tool-bar button in emacs. I can run it with eval-buffer but not with my .emacs. When i add it with eval-buffer my button leave my...

Match start-of-search position in elisp regexp

regex,elisp
I am doing some parsing in elisp, and I have a string that I have partially consumed (let's assume its value is "foobar123"). Suppose that I've consumed the "foobar" (so I know that I need to start parsing from char 6) and am expecting to consume a 2. I've tried...

Emacs bindings documentation

emacs,elisp
I am writing some bindings to lambdas in my ~/.emacs and would like to have a description of what the function does appear when I do (for example) C-c ?. I tried to put a string immediately after lambda () but that still does nothing. How do I get something...

Exceed evaluation depth when forward function in Emacs Lisp

emacs,lisp,elisp
Here is just a simplified code snipped I have not managed to work. I do not understand what is wrong. (defun enumerate-indicies (func) (let ((index 0)) (while (< index 5) (funcall func index) (setq index (1+ index))))) (defun enumerate-multiplied-indicies (func) (enumerate-indicies #'(lambda (index) (funcall func (* 10 index))))) The following...

custom-set-variables add blank space on subsequent uses

emacs,elisp
I followed the emacs haskell tutorial, and couldn't understand some of its language regarding the use of custom-set-variables in the text quoted below. It seems that custom-set-variables should be used in one way on first usage, and another way (with added blank space) on subsequent uses. My questions are: What...

Semi-colon goes to centre after return in elisp buffer

emacs,elisp
I just started having a problem with semi-colons in elisp buffers. I enter a semi-colon, ';', and hit return at which point the semi-colon gets centered. I am running the Gnu for OS X build :- This is GNU Emacs 24.4.1 (x86_64-apple-darwin13.4.0, NS apple-appkit-1265.21) of 2014-10-21 on builder10-9.porkrind.org I am...

Emacs: load package only for given major mode in init.el

emacs,elisp
I made some time ago a .el file (epx.el) for some files with a specific format that I am using. I load it in my init.el through (require 'epx). The problem is that in this epx.el, there is: (defadvice comment-region (after indent-after activate) (indent-region beg end) ) (defadvice uncomment-region (after...

emacs ow can I helm-find with default directory pre-specified?

emacs,elisp,helm
I use emacs for notes mainly. All my notes are in: ~/Dropbox/Uni/Notes I want to tie a keyboard shortcut (e.g C-f12) to do a helm-find that always starts in the above dir irrelevant of the source buffer. I have tried: (global-set-key (kbd "C-<f2>") (lambda () (interactive) (helm-find "~/Dropbox/Uni/Notes/"))) But when...

Text properties in interactive mode

emacs,elisp
How can i get the text properties values in interactive mode (for character in (point) for (current-buffer)? run functions like, get-text-property, get-char-property, get-pos-property .... etc in M-x mode?

How to refactor a sequence of add-to-list calls into a let?

elisp
I'm basically looking to refactor the below: (eval-after-load 'find-file-in-project '(progn (add-to-list 'ffip-patterns "*.clj") (add-to-list 'ffip-patterns "*.erb") (add-to-list 'ffip-patterns "*.haml") (add-to-list 'ffip-patterns "Gemfile*") (add-to-list 'ffip-patterns "*.css") (add-to-list 'ffip-patterns "*.scss") (add-to-list 'ffip-patterns "*.sass") (add-to-list 'ffip-patterns "*.rake") (add-to-list 'ffip-patterns "*.thor") (add-to-list 'ffip-patterns "Capfile") (add-to-list 'ffip-patterns "*.gemspec") (add-to-list 'ffip-patterns...

How to pass font-spec attributes as arguments to set-face-attribute?

elisp
Suppose that I have some font-spec in a variable my-font-spec. E.g. (setq my-font-spec (font-spec :family "XYZ" :height 120 :weight 'normal :width 'normal)) I want to pass the attributes in this font-spec as the &rest arguments to set-face-attribute. IOW, I want to, in effect, invoke (set-face-attribute some-face nil :family "XYZ" :height...

Is there a region change hook in emacs lisp?

emacs,elisp
I'm trying to get the content of current selected region in buffer. I'm aware of idle timer, but a hook should be more efficient/cleaner...

what's difference between 'delete' and 'remove' in Emacs Lisp

emacs,elisp
I am learning Elisp by reading others' code. Then I found people use both delete and remove to delete element from sequence. I checked the document and the code of remove it seams just a wrapper for delete which when the sequence is a list, do a copy-sequence. Is it...

Emacs and eww, open links in new window?

browser,emacs,elisp,org-mode,key-bindings
I configured Emacs to open new links in eww like so: (setq browse-url-browser-function 'eww-browse-url) Now when I click on a link, it opens in the same buffer. I would like it to open a new window (i.e split vertically like C - x 3) and open the page in the...

Is it possible to turn off qualification of symbols when using clojure syntax quote in a macro?

emacs,clojure,elisp
I am generating emacs elisp code from a clojure function. I originally started off using a defmacro, but I realized since I'm going cross-platform and have to manually eval the code into the elisp environment anyway, I can just as easily use a standard clojure function. But basically what I'm...

Looking for convenient way to define lexically scoped aliases for functions

elisp
I'm looking for the closest equivalent (both typographically and semantically) to what the following would do if functions in Elisp were "first-class": (let ((f function-with-very-long-name)) (progn ... (f ...) ;; evaluates to (function-with-very-long-name ...) ... ) ) IOW, I'm looking for a convenient way to define lexically scoped aliases for...

How to check if connected to remote server?

emacs,elisp,tramp
I use tramp to connect to my company's servers. I would like to customize my functions to work differently if I am accessing local files vs remote ones. Is there a variable I could check if the buffer I am accessing is on a remote server or my local machine?...