I would like all frames to overlap at (1,1). Yet with a .emacs containing
(setq initial-frame-alist
'((top . 1) (left . 1) (width . 80) (height . 55)))
(setq default-frame-alist
'((top . 1) (left . 1) (width . 80) (height . 55)))
calling C-x 5 2 results in frames in a cascade, as you see in the figure.
How can I force all frames to be anchored at the same place?
I am running Emacs 23.3.1 on OS X (Mountain Lion).
The settings are not being ignored. The reason you see the above behaviour is due to a before-make-frame-hook in ns-win.el that adds 25 to top and left.
To avoid the above effect you can add the following to your .emacs file:
(setq default-frame-alist '((left . 0) (top . 0) (width . 80) (height . 55)))
(defvar parameters)
(add-hook 'before-make-frame-hook
(lambda ()
(let ((left (cdr (assq 'left (frame-parameters))))
(top (cdr (assq 'top (frame-parameters)))))
(setq parameters (cons (cons 'left (+ left 0))
(cons (cons 'top (+ top 0))
parameters))))))
If the above doesn't work you can try the following which is taken from ns-win.el before-make-frame-hook.
(setq default-frame-alist '((left . 0) (top . 0) (width . 80) (height . 55)))
(defvar parameters)
(add-hook 'before-make-frame-hook
(lambda ()
(let ((left (cdr (assq 'left (frame-parameters))))
(top (cdr (assq 'top (frame-parameters)))))
(if (consp left) (setq left (cadr left)))
(if (consp top) (setq top (cadr top)))
(cond
((or (assq 'top parameters) (assq 'left parameters)))
((or (not left) (not top)))
(t
(setq parameters (cons (cons 'left (+ left 0))
(cons (cons 'top (+ top 0))
parameters))))))))
Related
I have my Emacs default new frame set to
(setq default-frame-alist
'((top . 150) (left . 400)
(width . 120) (height . 50)))
Is there a way to write a funciton to offset each new frame by 5 units at top and left so that each new frame will not be perfectly superimposed on top of each other? In other words, I want to cascade all new frames.
My system is OS X with Emacs 24.3.1
I suggest that you modify default-frame-alist in before-make-frame-hook:
(add-hook 'before-make-frame-hook 'cascade-default-frame-alist)
(defun cascade-default-frame-alist ()
(setq default-frame-alist
(mapcar (lambda (kv)
(if (memq (car kv) '(top left))
(cons (car kv) (+ 5 (cdr kv)))
kv))
default-frame-alist)))
If you want to modify default-frame-alist in-place, you need to create it with list instead of quote:
(setq default-frame-alist (list (cons 'top 150) (cons 'left 400)
(cons 'width 120) (cons 'height 50)))
(defun cascade-default-frame-alist ()
(dolist (kv default-frame-alist)
(when (memq (car kv) '(top left))
(setcdr kv (+ 5 (cdr kv))))))
I want to know the vertical position of the cursor relative to the top of the window. I tried this
(defun cursor-line-in-window ()
(save-excursion
(let* ((current-line (line-number-at-pos (point)))
(top-of-window-line (progn (move-to-window-line 0)
(line-number-at-pos (point)))))
(- current-line top-of-window-line))))
It works, except when I'm in an org-mode file where several lines are folded in under a headline. So I would like to either:
1: find a way to count the number of visible lines in a range, or
2: find a function that gives me the vertical position directly.
Look at (nth 6 (posn-at-point)), which should be a pair (COL . ROW).
Here you have a non-very-elegant solution:
(defun cursor-line-in-window ()
(save-excursion
(beginning-of-line)
(let ((pos (point))
(r 0))
(move-to-window-line 0)
(while (<= (point) pos)
(next-line 1)
(beginning-of-line)
(incf r))
r)))
In emacs flyspell mode, sometimes the list of suggestions is really long, so that the pop-up menu is taller than the screen and requires vertical scrolling of the menu because the "Save word" option is at the bottom of the menu.
Is there a way to to do one of the following:
Move "Save word" to the top of the menu?
Put a hard limit on the number of suggestions displayed?
Modify the threshold of a matching word?
This code will limit all ispell solutions to a maximum of limit-ispell-choices-to, which gets the desired limit in flyspell.
(defvar limit-ispell-choices-to 5
"Number indicating the maximum number of choices to present")
(defadvice ispell-parse-output (after limit-ispell-choices activate)
(when (and (listp ad-return-value)
ad-return-value)
(let* ((miss-list-end (nthcdr (- limit-ispell-choices-to 1)
(nth 2 ad-return-value)))
(guess-list-end (nthcdr (- limit-ispell-choices-to 1)
(nth 3 ad-return-value))))
(when miss-list-end (setcdr miss-list-end nil))
(when guess-list-end (setcdr guess-list-end nil)))))
This will put "Save word" at the top. I just swapped two words in the source.
It's a bit of a hack, but I can't see a better way.
(defun flyspell-emacs-popup (event poss word)
"The Emacs popup menu."
(unless window-system
(error "This command requires pop-up dialogs"))
(if (not event)
(let* ((mouse-pos (mouse-position))
(mouse-pos (if (nth 1 mouse-pos)
mouse-pos
(set-mouse-position (car mouse-pos)
(/ (frame-width) 2) 2)
(mouse-position))))
(setq event (list (list (car (cdr mouse-pos))
(1+ (cdr (cdr mouse-pos))))
(car mouse-pos)))))
(let* ((corrects (if flyspell-sort-corrections
(sort (car (cdr (cdr poss))) 'string<)
(car (cdr (cdr poss)))))
(cor-menu (if (consp corrects)
(mapcar (lambda (correct)
(list correct correct))
corrects)
'()))
(affix (car (cdr (cdr (cdr poss)))))
show-affix-info
(base-menu (let ((save (if (and (consp affix) show-affix-info)
(list
(list (concat "Save affix: " (car affix))
'save)
'("Accept (session)" session)
'("Accept (buffer)" buffer))
'(("Save word" save)
("Accept (session)" session)
("Accept (buffer)" buffer)))))
(if (consp cor-menu)
(append save (cons "" cor-menu))
save)))
(menu (cons "flyspell correction menu" base-menu)))
(car (x-popup-menu event
(list (format "%s [%s]" word (or ispell-local-dictionary
ispell-dictionary))
menu)))))
I search how to transparent my emacs window. But it doesn't work.
Something like this failed:
(global-set-key [(f8)] 'loop-alpha)
(setq alpha-list '((100 100) (95 65) (85 55) (75 45) (65 35)))
(defun loop-alpha ()
(interactive)
(let ((h (car alpha-list)))
((lambda (a ab)
(set-frame-parameter (selected-frame) 'alpha (list a ab))
(add-to-list 'default-frame-alist (cons 'alpha (list a ab)))
) (car h) (car (cdr h)))
(setq alpha-list (cdr (append alpha-list (list h))))
)
)
Here's a working implementation of what I think you were trying to do:
(global-set-key [(f8)] 'loop-alpha)
(defvar alpha-list '((100 100) (95 65) (85 55) (75 45) (65 35)))
(defun next-alpha ()
(let ((current-alpha
(or (frame-parameter (selected-frame) 'alpha)
(first alpha-list)))
(lst alpha-list))
(or (second
(catch 'alpha
(while lst
(when (equal (first lst) current-alpha)
(throw 'alpha lst))
(setf lst (cdr lst)))))
(first alpha-list))))
(defun loop-alpha ()
(interactive)
(let ((new-alpha (next-alpha))
(current-default (assoc 'alpha default-frame-alist)))
(set-frame-parameter (selected-frame) 'alpha new-alpha)
(if current-default
(setcdr current-default new-alpha)
(add-to-list 'default-frame-alist (cons 'alpha new-alpha)))))
Notice that any version you write that redefines alpha-list is going to behave very strangely with multiple frames. I would explain what was wrong with your code, but I honestly couldn't work out what it was supposed to do. Note that this would be somewhat easier to write if I allowed myself to (require 'cl) first, but I think this code should work - it does here at any rate!
Is there a way for Emacs to detect the current keyboard layout?
I often write texts in English and German, switching the (Win OS) keyboard layout. However, some functions (C-Y e.g.) should always be at the same physical key, no matter what language Im currently typing in.
Thanks
Consider using M-x set-input-method and M-x toggle-input-method. Toggle is bound to C-\, set is bound to C-x RET C-\. I recommend this binding, if you have hyper key:
(global-set-key [?\H-\\] 'set-input-method).
If you asking not how to type in different language, but how to make several commands work when you using different languages in your OS, try just to bind them. It worked nice on russian symbols. One black-black night i even wrote
(setq russian-symbols '(
(?й . ?q)
(?ц . ?w)
(?у . ?e)
(?к . ?r)
(?е . ?t)
(?н . ?y)
(?г . ?u)
(?ш . ?i)
(?щ . ?o)
(?з . ?p)
(?х . ?\[)
(?ъ . ?\])
(?ф . ?a)
(?ы . ?s)
(?в . ?d)
(?а . ?f)
(?п . ?g)
(?р . ?h)
(?о . ?j)
(?л . ?k)
(?д . ?l)
(?ж . ?\;)
(?э . ?')
(?я . ?z)
(?ч . ?x)
(?с . ?c)
(?м . ?v)
(?и . ?b)
(?т . ?n)
(?ь . ?m)
(?б . ?,)
(?ю . ?.)
(?Й . ?Q)
(?Ц . ?W)
(?У . ?E)
(?К . ?R)
(?Е . ?T)
(?Н . ?Y)
(?Г . ?U)
(?Ш . ?I)
(?Щ . ?O)
(?З . ?P)
(?Х . ?{)
(?Ъ . ?})
(?Ф . ?A)
(?Ы . ?S)
(?В . ?D)
(?А . ?F)
(?П . ?G)
(?Р . ?H)
(?О . ?J)
(?Л . ?K)
(?Д . ?L)
(?Ж . ?:)
(?Э . ?\")
(?Я . ?Z)
(?Ч . ?X)
(?С . ?C)
(?М . ?V)
(?И . ?B)
(?Т . ?N)
(?Ь . ?M)
(?Б . ?<)
(?Ю . ?>)
(?Ё . ?~)
(?ё . ?`)
))
(setq russian-symbols-full (append russian-symbols
'((?. . ?/)
(?, . ??)
(?\" . ?#)
(?№ . ?#)
(?\; . ?$)
(?: . ?^)
(?\? . ?&))))
(defun cm-ru-to-en-string(string)
(apply 'concat (mapcar (lambda (arg) (setq arg (format "%c" (or (cdr (assoc arg russian-symbols-full)) arg)))) string)))
(defun cm-en-to-ru-string(string)
(apply 'concat (mapcar (lambda (arg) (setq arg (format "%c" (or (car (rassoc arg russian-symbols-full)) arg)))) string)))
(defun cm-ru-to-en-region()
(interactive)
(let ((text (buffer-substring-no-properties (mark) (point))))
(delete-region (mark) (point))
(insert (cm-ru-to-en-string text))))
(defun cm-en-to-tu-region()
(interactive)
(let ((text (buffer-substring-no-properties (mark) (point))))
(delete-region (mark) (point))
(insert (cm-en-to-ru-string text))))
;; DO NOT USE vvv SINCE YOU WILL NOT BE ABLE TO INPUT THROUGH C-\
;; (let ((symbols russian-symbols))
;; (while symbols
;; (global-set-key (vector (car (car symbols))) (vector (cdr (car symbols))))
;; (setq symbols (cdr symbols))))
;; DO NOT USE ^^^ SINCE YOU WILL NOT BE ABLE TO INPUT THROUGH C-\
;; (- ?\C-ы ?ы) ;;russian C-
;; (- ?\C-s ?s) ;;english C-
;; (- ?\M-ы ?ы) ;;russian M-
;; (- ?\M-s ?s) ;;english M-
(setq russian-symbols-map1
(append
(mapcar (lambda (arg) (setq arg (cons (+ (- ?\C-ы ?ы) (car arg)) (+ (- ?\C-s ?s) (cdr arg))))) russian-symbols)
(mapcar (lambda (arg) (setq arg (cons (+ (- ?\M-ы ?ы) (car arg)) (+ (- ?\M-s ?s) (cdr arg))))) russian-symbols)
(mapcar (lambda (arg) (setq arg (cons (+ (- ?\C-\M-ы ?ы) (car arg)) (+ (- ?\C-\M-s ?s) (cdr arg))))) russian-symbols)
(mapcar (lambda (arg) (setq arg (cons (+ (- ?\H-ы ?ы) (car arg)) (+ (- ?\H-s ?s) (cdr arg))))) russian-symbols)
(mapcar (lambda (arg) (setq arg (cons (+ (- ?\H-\C-ы ?ы) (car arg)) (+ (- ?\H-\C-s ?s) (cdr arg))))) russian-symbols)
(mapcar (lambda (arg) (setq arg (cons (+ (- ?\H-\M-ы ?ы) (car arg)) (+ (- ?\H-\M-s ?s) (cdr arg))))) russian-symbols)
(mapcar (lambda (arg) (setq arg (cons (+ (- ?\H-\C-\M-ы ?ы) (car arg)) (+ (- ?\H-\C-\M-s ?s) (cdr arg))))) russian-symbols)))
(setq russian-symbols-map2
(append
russian-symbols-map1
russian-symbols)) ; We must not start with russian letters, but if it is element in a sequence - in should be fine.
(setq symbols2 russian-symbols-map1) ; One-key sequence command.
(let ((symbols2 russian-symbols-map1))
(while symbols2
(if
(and (symbolp (lookup-key global-map
(vector
(cdr (car symbols2))
)))
(lookup-key global-map
(vector
(cdr (car symbols2))
)))
(global-set-key
(vector
(car (car symbols2))
)
(lookup-key global-map
(vector
(cdr (car symbols2))
))))
(setq symbols2 (cdr symbols2))))
(let ((symbols1 russian-symbols-map2) (symbols2 russian-symbols-map1)) ; Two keys sequence
(while symbols1
(while symbols2
(if
(and (symbolp (lookup-key global-map
(vector
(cdr (car symbols2))
(cdr (car symbols1))
)))
(lookup-key global-map
(vector
(cdr (car symbols2))
(cdr (car symbols1))
)))
(global-set-key
(vector
(car (car symbols2))
(car (car symbols1))
)
(lookup-key global-map
(vector
(cdr (car symbols2))
(cdr (car symbols1))
))))
(setq symbols2 (cdr symbols2)))
(setq symbols2 russian-symbols-map1)
(setq symbols1 (cdr symbols1))))
(provide 'shamanizm) ;russian emacs-users should lol reading this
It works. I've binded all global hotkeys up to 2 level with russian symbols.
I am not using it now, it eat startup time, and it ruins readability of my *Help* with crazy things like It is bound to C-x b, C-x и, C-ч b, C-ч и. Use it wisely.