2


我正在努力为我的 mac 调整我的 emacs conf 文件......
我想要做的是能够通过使用 ctrl + 箭头按块向上/向下滚动。问题是,当我尝试这样做时,mac 会拦截命令并执行特定于 mac os 的操作......
这是我当前的 .emacs 文件:

(add-to-list 'load-path "~/.emacs.d/")

(setq column-number-mode t)
(setq shift-select-mode t)
(show-paren-mode 1)
(global-linum-mode 1)
(set-face-attribute 'linum nil :background "#000000")
(setq linum-format
      (lambda (line)
    (propertize (format
             (let ((w (length (number-to-string
                       (count-lines (point-min) (point-max))))))
               (concat "%" (number-to-string w) "d    "))
             line)
            'face 'linum)))

(add-to-list 'auto-mode-alist (cons "\\.php[0-9]*$" 'php-mode))

(global-set-key "" 'do_insert_time)
(global-set-key "" 'std-file-header)

(setq header-made-by    "Made by "
  header-login  "Login   "
  header-login-beg  "<"
  header-login-mid  "@"
  header-login-end  ">"
  header-started    "Started on  "
  header-last   "Last update "
  header-for    " for "
  header-in     " in "
  domaine-name  "")
(if (setq user-nickname (getenv "USER_NICKNAME"))
    t 
  (setq user-nickname (user-full-name))
)

(setq write-file-hooks (cons 'update-std-header write-file-hooks))

(setq std-c-alist               '( (cs . "/*") (cc . "** ") (ce . "*/") )
  std-css-alist             '( (cs . "/*") (cc . "** ") (ce . "*/") )
  std-cpp-alist             '( (cs . "//") (cc . "// ") (ce . "//") )
  std-pov-alist             '( (cs . "//") (cc . "// ") (ce . "//") )
  std-java-alist            '( (cs . "//") (cc . "// ") (ce . "//") )
  std-latex-alist           '( (cs . "%%") (cc . "%% ") (ce . "%%") )
  std-lisp-alist            '( (cs . ";;") (cc . ";; ") (ce . ";;") )
  std-xdefault-alist        '( (cs . "!!") (cc . "!! ") (ce . "!!") )
  std-pascal-alist          '( (cs . "{ ") (cc . "   ") (ce . "}" ) )
  std-makefile-alist        '( (cs . "##") (cc . "## ") (ce . "##") )
  std-text-alist            '( (cs . "##") (cc . "## ") (ce . "##") )
  std-fundamental-alist     '( (cs . "  ") (cc . "   ") (ce . "  ") )
  std-html-alist            '( (cs . "<!--") (cc . "  -- ") (ce . "-->"))
  std-php-alist     '( (cs . "#!/usr/local/bin/php\n<?php") (cc . "// ")(ce . "//"))
  std-nroff-alist           '( (cs . "\\\"") (cc . "\\\" ") (ce . "\\\""))
  std-sscript-alist         '( (cs . "#!/bin/sh")  (cc . "## ") (ce . "##"))
  std-perl-alist            '( (cs . "#!/usr/local/bin/perl -w")  (cc . "## ")(ce . "##"))
  std-cperl-alist           '( (cs . "#!/usr/local/bin/perl -w")  (cc . "## ")(ce . "##"))
  )


(setq std-modes-alist '(("C"                    . std-c-alist)
        ("C/l"                  . std-c-alist)
                    ("CSS"                  . std-c-alist)
                    ("PoV"                  . std-pov-alist)
                    ("C++"                  . std-cpp-alist)
                    ("C++/l"                . std-cpp-alist)
                    ("Lisp"                 . std-lisp-alist)
                    ("Lisp Interaction"     . std-lisp-alist)
                    ("Emacs-Lisp"           . std-lisp-alist)
                    ("Fundamental"          . std-fundamental-alist)
                    ("Shell-script"         . std-sscript-alist)
                    ("Makefile"             . std-makefile-alist)
        ("GNUmakefile"      . std-makefile-alist)
                    ("BSDmakefile"          . std-makefile-alist)
                    ("Perl"                 . std-cperl-alist)
                    ("CPerl"                . std-cperl-alist)
                    ("xdefault"             . std-xdefault-alist)
                    ("java"                 . std-java-alist)
                    ("latex"                . std-latex-alist)
                    ("Pascal"               . stdp-ascal-alist)
                    ("Text"                 . std-text-alist)
                    ("HTML"                 . std-html-alist)
        ("PHP"                 . std-php-alist)
                    ("Nroff"                . std-nroff-alist)
                    ("TeX"                  . std-latex-alist)
                    ("LaTeX"                . std-latex-alist))
  )

(defun std-get (a)
  (interactive)
  (cdr (assoc a (eval (cdr (assoc mode-name std-modes-alist)))))
  )

(defun update-std-header ()
  "Updates std header with last modification time & owner.\n(According to mode)"
  (interactive)
  (save-excursion
    (if (buffer-modified-p)
        (progn
          (goto-char (point-min))
          (if (search-forward header-last nil t)
              (progn
;               (delete-region (point-at-bol) (point-at-eol))                                                                                                                   
                (delete-region
                 (progn (beginning-of-line) (point))
                 (progn (end-of-line) (point)))
                (insert-string (concat (std-get 'cc)
                                      header-last
                                       (current-time-string)
                                       " "
                                       user-nickname))
                (message "Last modification header field updated."))))))
  nil)

(defun std-file-header ()
  "Puts a standard header at the beginning of the file.\n(According to mode)"
  (interactive)
  (goto-char (point-min))
  (let ((projname "toto")(location "tiuti"))
    (setq projname (read-from-minibuffer
            (format "Type project name (RETURN to quit) : ")))
    (setq location (getenv "PWD"))

    (insert-string (std-get 'cs))
    (newline)
    (insert-string (concat (std-get 'cc)
               (buffer-name)
           header-for
           projname
           header-in
           location))
    (newline)
    (insert-string (std-get 'cc))
    (newline)
    (insert-string (concat (std-get 'cc) header-made-by user-nickname))
    (newline)
    (insert-string (concat (std-get 'cc)
           header-login
           header-login-beg
           (getenv "USER")
           header-login-mid
           domaine-name
           header-login-end))
    (newline)
    (insert-string (std-get 'cc))
    (newline)
    (insert-string (concat (std-get 'cc)
           header-started
           (current-time-string)
           " "
           user-nickname))
    (newline)
    (insert-string (concat (std-get 'cc)
           header-last
           (current-time-string)
           " "
           user-nickname))
    (newline)
    (insert-string (std-get 'ce))
    (newline)))

(defun insert-std-vertical-comments ()
  "Inserts vertical comments (according to mode)."
  (interactive)
  (beginning-of-line)
  (insert-string (std-get 'cs))
  (newline)
  (let ((ok t)(comment ""))
    (while ok
      (setq comment (read-from-minibuffer
             (format "Type comment (RETURN to quit) : ")))
      (if (= 0 (length comment))
      (setq ok nil)
    (progn
      (insert-string (concat (std-get 'cc) comment))
      (newline)))))
  (insert-string (std-get 'ce))
  (newline))

(defun std-toggle-comment ()
  "Toggles line comment on or off (according to mode)."
  (interactive)
  (save-excursion
    (let (beg end)
      (beginning-of-line)
      (setq beg (point))
      (end-of-line)
      (setq end (point))
      (save-restriction
    (if (not (equal beg end))
        (progn
      (narrow-to-region beg end)
      (goto-char beg)
      (if (search-forward (std-get 'cs) end t)
      (progn
        (beginning-of-line)
        (replace-string (std-get 'cs) "")
        (replace-string (std-get 'ce) ""))
    (progn
      (beginning-of-line)
      (insert-string (std-get 'cs))
      (end-of-line)
      (insert-string (std-get 'ce))))))))) 
  ;;  (indent-according-to-mode)
  (indent-for-tab-command)
  (next-line 1))

;;; Added by Eole Wednesday May 29 2002,  1:33:55
;;; Extended bindings for this package and for commenting code

(global-set-key "h" 'update-std-header)
(global-set-key "" 'std-file-header)

;;;; Generating local keymaps for exotics modes.

;;; In CPerl mode, C-c C-h is used to do some help.
;;; so it is C-c C-h h
;;; For working, it requires info pages about perl
(add-hook 'cperl-mode-hook
      '(lambda ()
         (define-key cperl-mode-map ""
       'comment-region)
     (define-key cperl-mode-map "h"
       'std-file-header)))

;; for perl-mode
(add-hook 'perl-mode-hook
  '(lambda ()
     (define-key perl-mode-map ""
       'comment-region)))

;; for all kind of lisp code
(add-hook 'emacs-lisp-mode-hook
  '(lambda ()
     (define-key emacs-lisp-mode-map  ""
       'comment-region)))

(add-hook 'lisp-mode-hook
  '(lambda ()
     (define-key lisp-mode-map  ""
       'comment-region)))



;; for La(TeX)-mode
(add-hook 'tex-mode-hook
  '(lambda ()
     (define-key tex-mode-map ""
       'comment-region)))



(custom-set-variables
  ;; custom-set-variables was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(inhibit-startup-screen t))
(custom-set-faces
  ;; custom-set-faces was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 )

非常感谢!

4

2 回答 2

2

在系统偏好设置中重新分配或禁用“任务控制”和“应用程序窗口”键盘快捷键。

Mac OS X Mountain Lion 的系统偏好设置截图

演示键盘快捷键自定义的屏幕截图

于 2012-12-14T00:38:29.383 回答
0

绑定 Ctrl-up 和 -down 的常规方法是通过.emacs文件中的以下行:

(global-set-key "C-<up>" 'scroll-down)
(global-set-key "C-<down>" 'scroll-up)

这在 Emacs 直接从操作系统接收所有击键时有效。如果 emacs 在终端内运行,它还取决于终端设置。describe-key您可以使用 Emacs 命令(键盘快捷键Ctrl-h k)以及要使用的组合键(例如Ctrl-up )测试 Emacs 实例接收到的键。如果像我怀疑的那样,帮助窗口只提到<up>而不是<C-up>,则终端设置会删除 Ctrl 修饰符。

我建议你最好的改变是安装一个 emacs 构建,它作为一个像emacsformacosx这样的 Carbon 应用程序运行。

那么上面列出的绑定应该可以工作。

于 2012-11-09T00:48:18.547 回答