保持Emacs窗口大小

本文提供了一个解决方案,用于解决在Windows环境下使用emacsclient打开文件时,原本最大化且最小化的Emacs窗口恢复时变为非最大化的问题。通过修改Emacs的设置,确保窗口能够保持最大化状态。
windows下用emacsclient打开文件时, 如果当前的Emacs frame原来是最大化的而且当前正被最小化到windows的taskbar, 那么这个frame就会被还原成非最大化状态。解决方法(jcjbrian@newsmth):

;; 2008-4-15
;; Brian Jiang

;; When the emacs frame was maximized and is currently minimized into
;; the TaskBar
, if opening a file from emacsclient, the frame then is
;; restored down to non maximized status
. This is not the behavior
;; that most of us expect
. In this case, we want the emacs frame keep
;; in the maximized status when it is restore from minimized
.

;; So
? Hack Emacs a little to let it behave as we expect....

;; The best solution will be to change the C codes
. e.g., procedure
;; x_make_frame_visible
. When the frame is currently minimized, use
;; SW_RESTORE instead of SW_SHOWNORMAL to show the window
.


;; (defun 
select-frame-set-input-focus (frame)
;;   
"Select FRAME, raise it, and set input focus, if possible."
;;     (
select-frame frame)

;;     ;; Brian
: change 1/1
;;     ;; (raise
-frame frame)
;;     (cond ((eq (cdr (assq 
'visibility (frame-parameters))) t)
;;            (raise-frame frame))
;;           (t
;;            ;; SC_RESTORE
;;            (w32-send-sys-command 61728)
;;            ))
;;     ;; Brian: end of change 1/1
;;     (debug)
;;     ;; Ensure, if possible, that frame gets input focus.
;;     (cond ((memq window-system 
'(x mac))
;;        (x
-focus-frame frame))
;;       ((eq window
-system 'w32)
;;        (w32-focus-frame frame)))
;;     (cond (focus-follows-mouse
;;        (set-mouse-position (selected-frame) (1- (frame-width)) 0))))


(defadvice raise-frame (around raise-frame (&optional frame))
  (cond ((eq (cdr (assq 
'visibility (frame-parameters frame))) t)
         ad
-do-it)
        (t
         ;; SC_RESTORE
         (w32
-send-sys-command 61728)
         )))

(ad
-activate 'raise-frame)

(require 
'server)
;; overide the function server
-visit-files in server.el
(defun server
-visit-files (files client &optional nowait)
  
"Find FILES and return the list CLIENT with the buffers nconc'd.
FILES is an alist whose elements are (FILENAME LINENUMBER COLUMNNUMBER).
NOWAIT non-nil means this client is not waiting for the results,
so don't mark these buffers specially, just visit them normally.
"
  ;; 
Bind last-nonmenu-event to force use of keyboard, not mouse, for queries.
  (let ((
last-nonmenu-event t) client-record)
    ;; Restore the current buffer afterward
, but not using save-excursion,
    ;; because we don
't want to save point in this buffer
    ;; if it happens to be one of those specified by the server.
    (save-current-buffer
      (dolist (file files)
    ;; If there is an existing buffer modified or the file is
    ;; modified, revert it.  If there is an existing buffer with
    ;; deleted file, offer to write it.
    (let* ( ;; (minibuffer-auto-raise (or server-raise-frame  ;; brian
               ;; minibuffer-auto-raise))                        ;; brian
               (filen (car file))
               (obuf (get-file-buffer filen)))
          
      (add-to-history 
'file-name-history filen)
      (
if (and obuf (set-buffer obuf))
          (progn
        (cond ((file
-exists-p filen)
                       (when (not (verify
-visited-file-modtime obuf))
                         ;; brian
, hack...
                         (when (and server
-raise-frame
                                    (not (eq (cdr (assq 
'visibility (frame-parameters))) t)))
                           (w32-send-sys-command 61728)
                           (sit-for 0.1))
                         (let ((minibuffer-auto-raise (or server-raise-frame minibuffer-auto-raise)))
                           (revert-buffer t nil))))
              (t
                       ;; brian, hack...
                       (when (and server-raise-frame
                                  (not (eq (cdr (assq 
'visibility (frame-parameters))) t)))
                         (w32
-send-sys-command 61728)
                         (sit
-for 0.1))
                       (let ((minibuffer
-auto-raise (or server-raise-frame minibuffer-auto-raise)))
                         (when (y
-or-n-p
                                (concat 
"File no longer exists: "
                                        filen
                                        
", write buffer to file? "))
                           (
write-file filen)))))
        (setq server
-existing-buffer t)
        (server
-goto-line-column file))
        (set
-buffer (find-file-noselect filen))
        (server
-goto-line-column file)
        (run
-hooks 'server-visit-hook)))
    (unless nowait
      ;; When the buffer is killed, inform the clients.
      (add-hook 
'kill-buffer-hook 'server-kill-buffer nil t)
      (push (car client) server-buffer-clients))
    (push (current-buffer) client-record)))
    (nconc client client-record)))
上面的代码可以单独作一个文件,让Emacs启动是加载它,那么在使用emacsclient时就不会出现窗口大小改动的现象了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值