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?
If you simply want to see what text properties there is at a specific point, place the cursor there and issue C-u C-x =.
Otherwise, you can run arbitrary elisp interactively by M-: (get-text-property (point) 'face) RET.
Related
I usually have 2-3 windows open in emacs, and am particular about which buffer is shown where. While C-x C-f shows the buffer (file visited) in the current window, C-x C-b (and recentf-open-files from the recentf package) sometimes end up displaying it in another window, which then makes complicated rearrangements necessary.
Is there a way to force these commands to end up displaying the buffer in the window that was active when the C-x C-f or C-x C-b where issued?
The function at issue list-buffers is a one-liner -- so just change display-buffer to switch-to-buffer and redefine the keyboard shortcut to point to the new function:
(defun my-list-buffers (&optional arg)
"Display a list of existing buffers.
The list is displayed in a buffer named \"*Buffer List*\".
See `buffer-menu' for a description of the Buffer Menu.
By default, all buffers are listed except those whose names start
with a space (which are for internal use). With prefix argument
ARG, show only buffers that are visiting files."
(interactive "P")
(switch-to-buffer (list-buffers-noselect arg)))
(define-key ctl-x-map "\C-b" 'my-list-buffers)
How can I open a new window (for example using C-x 3) into a new buffer, rather than a mirrored buffer that just echoes what I type.
So for example, let's say I'm messing around with python and I want to run the script in the shell. As it is currently I do this: C-x 3, M-x shell and then start it up and running. I'd rather just C-x 3 and it automatically opens into shell. I'm really new to Emacs so I don't know where to look for this.
It sounds to me like this, or something similar, is what you are looking for:
(defun pop-to-buff-at-right (buffer)
"Pop to BUFFER at the right of the current window."
(interactive "B")
(pop-to-buffer buffer '(display-buffer-in-side-window
(side . right)
(inhibit-same-window . t))))
You do not want to just split the window, which is specifically about showing the same buffer twice. You want to switch to another buffer, but you want it to be displayed to the right of the current window.
In emacs it is easy to define custom commands and bind it to keys. For instance, if you add this to your init file:
(defun open-shell-at-left ()
(interactive) ;; Tell emacs this function can be called interactively
(split-window-right) ;; Just what C-x 3 does
(shell)) ;; Just what M-x shell does
(global-set-key (kbd "C-c 3") 'open-shell-at-left)
You will have what you want when you type C-c 3. In general, you can find documentation about what a key binding does by typing C-h k and the keybinding. From that point, it is easy to chain existing commands into new ones.
I am basically looking for the Scheme equivalent of C-u C-x C-e in the clojure/nrepl mode, or C-c C-p.
I want a C-x C-e that prints the output to the buffer as opposed to just in the repl.
Use
(require 'cmuscheme)
(setq scheme-program-name "/usr/local/<path-to-a-scheme>")
then within a Scheme file, in the Scheme Major Mode, there should be a 'Scheme' menu that shows all the key bindings. To 'Evaluate Last S Expression' you'll use C-x C-e. The result will not be in the Scheme file's source, it will be in the *scheme* buffer running the inferior Scheme.
I realize that SLIME is the Superior Lisp Interaction Mode but I'm wondering if there is a "Lisp Interaction" buffer that works with Common Lisp like the *scratch* buffer works with Emacs Lisp. I.E. hitting C-j at the end of a form will insert the result of that form in the current buffer.
I ask because I find editing the output as needed is easier this way than with the repl.
There is M-xslime-scratchRET though I don't
know what does C-j by default because I use
Paredit.
However C-uC-xC-e does what you want in
both *scratch* and *slime-scratch*.
It is bound to C-x C-e.
(eval-last-sexp EVAL-LAST-SEXP-ARG-INTERNAL)
Evaluate sexp before point; print value in minibuffer.
Interactively, with prefix argument, print output into current buffer.
Truncates long output according to the value of the variables
`eval-expression-print-length' and `eval-expression-print-level'.
(and it's slime-eval-last-expression in the *slime-scratch* buffer)
Binding this function to C-j does the behaviour that I'm looking for:
(defun slime-eval-print-last-sexp ()
(interactive)
(newline)
(insert (cadr (slime-eval `(swank:eval-and-grab-output ,(slime-last-expression)))))
(newline))
I have a text file. Can Emacs select text based on regex and put it in kill-ring, so I can copy it somewhere else? Something like regex-kill-ring-save?
inspired by the already given comments (the Charles answer doesn't work as I would want it), I added a new function to the isearch/isearch-regexp mode map which puts only the matching string into the kill ring (whereas Charles proposal kills from current point to end of matching string):
(defun hack-isearch-kill ()
"Push current matching string into kill ring."
(interactive)
(kill-new (buffer-substring (point) isearch-other-end))
(isearch-done))
(define-key isearch-mode-map (kbd "M-w") 'hack-isearch-kill)
The nice thing about the isearch/isearch-regexp approach (which you can enable with C-s and C-M-s respectively) is that you can see your search string growing and you can copy it with M-w as soon as you are satisfied (and go back to where you have been before with C-u C-Space).
This works for me with Emacs 23.1. Don't know if it will work in all situations. Anyway I hope you find it useful :)
UPDATE: going through the emacswiki I stumbled over KillISearchMatch which suggests more or less the same (plus some more tips ...).
Cheers,
Daniel
I'm not sure if there is such a function already, but what you can do it with a keyboard macro:
Start recording a kbd macro: C-x (
Search for your regexp with search-forward-regexp
Move to the beginning of your match (the text you want to kill) with the various emacs navigation commands, e.g. search or backward-word etc.
Mark: C-spc
Move to the end of your match
Kill the text: C-w
You can then name the keyboard macro with M-x name-last-kbd-macro so that you can execute the macro with a name rather than with C-x e.
If you want to save the macro for future sessions, you can open your .emacs and insert the macro into the buffer with M-x insert-kbd-macro. After than you can bind a key to the macro just like you bind keys to normal emacs functions, e.g. (global-set-key "\C-c m" 'funky-macro-macro).
More about emacs keyboard macros
Isearch+ does this already. It optionally sets the region around the search target. You can use C-SPC C-SPC or M-= C-SPC at any time during Isearch to toggle this.
isearchp-deactivate-region-flag is a variable defined in isearch+.el.
Its value is t
Documentation:
Non-nil means isearching deactivates the region.
See also option isearchp-restrict-to-region-flag.
You can toggle this option using M-= C-SPC during Isearch.
You can customize this variable.