elisp

Using Emacs to indent (shift 4) code

微笑、不失礼 提交于 2019-11-29 01:36:28
I edit my StackOverflow answers and questions with ViewSourceWith and Emacs. Often, I include code and StackOverflow formatting rules say that it must be indented by four spaces to be recognized as such. Doing it by hand or even with macros is painful. I searched in SO's previous postings but found nothing. Starting from the Python mode, I wrote: (defun text-shift-region (start end count) "Indent lines from START to END by COUNT spaces." (save-excursion (goto-char end) (beginning-of-line) (setq end (point)) (goto-char start) (beginning-of-line) (setq start (point)) (indent-rigidly start end

how to align arguments to functions in emacs?

馋奶兔 提交于 2019-11-29 01:00:29
问题 Say if I have the following: func(arg1, arg2, arg3...) func(longargarg1, longerarg2, arg3,...) ... How do I align the arguments so that it's like following? func(arg1 , arg2 , arg3...) func(longargarg1, longerarg2, arg3,...) ... [I can use M-x align-regex to align the first argument, but I cannot cook up with a suitable regex to align the rest of the arguments. Bonus point if the answer also take cares of the case when some arguments are strings with commas in them.] 回答1: Select the region,

Making JSON requests within Emacs

♀尐吖头ヾ 提交于 2019-11-29 00:22:54
问题 I am in the early stages of writing an Emacs major mode for browsing and contributing to sites on the Stack Exchange network, in much the same way as dired and list-packages works, with a few inspirations from magit and org-mode . The problem is, of course, I have no idea how I would interface Emacs with the SE API (v2.1) in the first place. I've never done anything that involves a network connection within Elisp, although I'm comfortable with the language itself (and have taken more than a

Can I detect the display size/resolution in Emacs?

谁都会走 提交于 2019-11-28 22:45:38
问题 I'd like to change the window/frame size of my XEmacs based on the current display resolution. This is useful when I run my laptop either by itself or attached to a docking station with an external monitor. In either situation, I'd like Emacs to detect the primary screen resolution and adjust its main window frame size accordingly when I start it up. 回答1: The current display resolution is available using the following functions (both non-interactive). (x-display-pixel-width) (x-display-pixel

Is there an Emacs Lisp library for generating HTML?

时光怂恿深爱的人放手 提交于 2019-11-28 21:19:51
问题 I'm looking for a solution that allows me to write native Emacs Lisp code and at compile time turns it into HTML, like Franz's htmlgen: (html ((:div class "post") (:h1 "Title") (:p "Hello, World!"))) Of course I can write my own macros, but I'm interested if there are any projects around this problem. 回答1: As you found out, xmlgen generates XML from a list structure. What I did find disappointing with the ``xmlgen` package that the format it supports is not quite the inverse of Emacs' xml

Get rid of “reference to free variable” byte-compilation warnings

强颜欢笑 提交于 2019-11-28 21:04:17
I'm writing an emacs major mode, which uses buffer-local variables to store some state: (defun foo-mode () "My nice major mode" (interactive) (kill-all-local-variables) (setq mode-name "foo") (setq major-mode 'foo-mode) (set (make-local-variable 'foo-state) "bar")) (defun foo-change-state () (setq foo-state "baz")) This works very well and has the property that in any buffer not using my major mode, the foo-state variable is not bound (which is a good thing in my opinion, since it avoids cluttering the symbols table). However, byte-compiling such a piece of code produces the following warning:

Emacs Lisp: How to add a folder and all its first level sub-folders to the load-path

99封情书 提交于 2019-11-28 20:40:48
If I have a folder structure set up like this: ~/Projects emacs package1 package1-helpers package2 package2-helpers package2-more-helpers package3 package3-helpers How do I add these folders: ~/Projects/emacs ~/Projects/emacs/package1 ~/Projects/emacs/package2 ~/Projects/emacs/package3 ...to the load-path from my .emacs file? I basically need a short automated version of this code: (add-to-list 'load-path "~/Projects/emacs") (add-to-list 'load-path "~/Projects/emacs/package1") (add-to-list 'load-path "~/Projects/emacs/package2") (add-to-list 'load-path "~/Projects/emacs/package3") (let ((base

Emacs :TODO indicator at left side

痴心易碎 提交于 2019-11-28 20:29:24
I want to have sort of indiacator at left side of the line wherever I have in the source code #TODO : some comment //TODO: some comments The indicator could be a just mark and I already enabled line numbers displayed at emacs. This command will do something like you want. (defun annotate-todo () "put fringe marker on TODO: lines in the curent buffer" (interactive) (save-excursion (goto-char (point-min)) (while (re-search-forward "TODO:" nil t) (let ((overlay (make-overlay (- (point) 5) (point)))) (overlay-put overlay 'before-string (propertize "A" 'display '(left-fringe right-triangle)))))))

Emacs: adding 1 to every number made of 2 digits inside a marked region

大憨熊 提交于 2019-11-28 20:03:18
问题 Imagine I've got the following in a text file opened under Emacs: some 34 word 30 another 38 thing 59 to 39 say 10 here 47 and I want to turn into this, adding 1 to every number made of 2 digits: some 35 word 31 another 39 thing 60 to 40 say 11 here 48 (this is a short example, my actual need is on a much bigger list, not my call) How can I do this from Emacs? I don't mind calling some external Perl/sed/whatever magic as long as the call is made directly from Emacs and operates only on the

Emacs custom command line argument

荒凉一梦 提交于 2019-11-28 19:31:59
From the documentation I can see I can access command line arguments (command-line-args). I'd like to add my own arguments but Emacs complains at start up that it doesn't recognize them. E.g. emacs -my_argument I get: command-line-1: Unknown option `-my_argument' What's a proper way to define my custom arguments and provide information to my Emacs session? Is there a way to pop an argument from a command line? Add something like this to your ~/.emacs , ~/.emacs.el , or ~/.emacs.d/init.el file: (defun my-argument-fn (switch) (message "i was passed -my_argument")) (add-to-list 'command-switch