Wed 20 August 2014

Emacs: Open file in browser

Inspiriert vom Idea-GitLab-Integration-Plugin, das ein open file in browser anbietet, habe ich das ganze mal für Emacs gebaut:

(require 'magit)

(setq git-browser-url-templates
      '(("" . "{{repo}}/src/{{branch}}/{{file-name}}#cl-{{lineno}}")
     ("" . "{{repo}}/blob/{{branch}}/{{file-name}}#L{{lineno}}")
     ("" . "{{repo}}.git;a=blob;f={{file-name}};hb={{branch}}#l{{lineno}}")))

(defun format-gitviewer-url (template vars)
  (let ((expand (lambda (match)
               (let* ((name (substring match 2 -2))
                      (value (assoc name vars)))
                 (unless value
                   (error (format "Unknown variable %s" name)))
                 (cdr value)))))
    (replace-regexp-in-string "{{.+?}}" expand template)))

(defun git-open-in-browser ()
  (let* ((remote (magit-get-remote nil))
      (remote-url (magit-get "remote" remote "url"))
      (branch (substring (magit-get-tracked-branch) (+ 1 (length remote))))
      (file-name (magit-file-relative-name (buffer-file-name)))
      (lineno (line-number-at-pos)))
    (unless (string-match "\\(@\\|://\\|^\\)\\([^:@/]+?\\)[:/]\\([^/].*?\\)\\(.git\\)?$" remote-url)
      (error "Could not find repo name"))
    (let* ((host-name (match-string 2 remote-url))
        (repo-name (match-string 3 remote-url))
        (url-template (assoc host-name git-browser-url-templates)))
      (unless url-template
     (error (format "Could not find URL template for host %s" host-name)))
      (browse-url (format-gitviewer-url (cdr url-template)
                                      (cons "repo" repo-name)
                                      (cons "branch" branch)
                                      (cons "file-name" file-name)
                                      (cons "lineno" (number-to-string lineno))))))))

Sat 13 March 2010

Skripte automatisch ausführbar machen


(add-hook 'after-save-hook 'executable-make-buffer-file-executable-if-script-p)

zur Konfiguration hinzufügen, dann werden Dateien mit Shebang automatisch beim Speichern ausführbar gemacht.

Wed 03 February 2010

GNU made my day

The file that would normally be displayed here (THE-GNU-PROJECT) has been moved to the emacs23-common-non-dfsg package because its license does not appear to be compatible with the Debian Free Software Guidelines (DFSG). Please see /usr/share/doc/emacs23-common/copyright for more information.

Please install THE-GNU-PROJECT from Debian's non-free distribution if you would like for Emacs to display the original file.