小编RNA*_*RNA的帖子

在elisp中压缩两个不同长度的列表

我有两个清单:

(setq x (list "a" "b" "c"))
(setq y (list "1" "2" "3" "4"))
Run Code Online (Sandbox Code Playgroud)

如何创建一个(("a" . "1") ("b" . "2") ("c" . "3") ("a" . "4"))使用较短列表回收的利弊单元列表?

elisp

6
推荐指数
1
解决办法
588
查看次数

如何用sphinx生成函数签名?

包结构和文件设置如下:

$ tree .
.
??? doc
?   ??? Makefile
?   ??? README.md
?   ??? _build
?   ??? _static
?   ??? conf.py
?   ??? foo.rst
?   ??? index.rst
?   ??? make.bat
??? foo
    ??? __init__.py
    ??? spam.py


$ cat foo/__init__.py
r'''
The Foo module
==============

.. autosummary::
   :toctree: generated

   spam
'''


$ cat foo/spam.py
r'''
The Spam Module
===============
'''

def prepare(a):
    '''Prepare function.

    Parameters
    ----------
    a : int
    '''
    print(a)


$ cat doc/index.rst
Welcome to foo's documentation!
=====================================

API …
Run Code Online (Sandbox Code Playgroud)

python documentation python-sphinx

6
推荐指数
1
解决办法
406
查看次数

Shell脚本中是否有任何机制在C++中使用"include guard"?

让我们看一个例子:在我的main.sh中,我想找一个a.sh和b.sh. 但是,a.sh可能已经采购了b.sh. 因此,它将导致b.sh中的代码执行两次.在C++中是否有类似"包含守卫"的机制?

shell include-guards

5
推荐指数
2
解决办法
1511
查看次数

独立的shell脚本与shell函数?

例如,我想编写一个bash shell脚本来使用进行轮换备份rsync。我应该将其作为独立脚本文件(backup.sh)还是将其包装在函数(backup)中?作为脚本文件,我可以运行它bash backup.sh。作为一项功能,我可以将其放置在诸如这样的文件中,foo.sh并在每次登录时将其作为源,然后我可以简单地backup作为命令运行以备份文件。问题是,这两种策略的利弊是什么?

或更笼统地说,我想知道在什么情况下应该将功能实现为独立的Shell脚本文件还是Shell函数?

我的一些想法:我知道某些图形会话(例如KDE,Gnome等)在登录时会生成不同的文件。如果要在以图形方式启动的应用程序中使用外壳程序功能(例如单击图标以打开emacs),可能会引起一些混乱。但是我更喜欢将其实现为shell函数,并将它们组合到文件中,我认为它们是整洁且组织良好的。

还有其他想法或建议吗?

bash shell function

5
推荐指数
1
解决办法
2019
查看次数

如何取消设置Emacs的空白模式的前景色

在编程文件中,我使用空白模式来突出显示选项卡和长行.默认突出显示对我来说太装饰了.我只想用灰色背景突出显示它们并保留它应该是字体的正常颜色.我该怎么设置?

以下设置不起作用.我希望超过80列的代码看起来偏黄,作为快照中80列内的字符.

;; face for long lines' tails
(set-face-attribute 'whitespace-line nil
                    :background "#555"
                    :weight 'bold)

;; face for Tabs
(set-face-attribute 'whitespace-tab nil
                    :background "#555"
                    :weight 'bold)
Run Code Online (Sandbox Code Playgroud)

空白模式

emacs whitespace long-lines

5
推荐指数
1
解决办法
1610
查看次数

减少冗余

我想为不同的字符定义一堆面孔,如下所示:

(defface char-face-a
  '((((type tty) (class color)) (:background "yellow" :foreground "black"))
    (((type tty) (class mono)) (:inverse-video t))
    (((class color) (background dark)) (:background "yellow" :foreground "black"))
    (((class color) (background light)) (:background "yellow" :foreground "black"))
    (t (:background "gray")))
  "Face for marking up A's"
  :group 'char-faces)

(defface char-face-b
  '((((type tty) (class color)) (:background "red" :foreground "black"))
    (((type tty) (class mono)) (:inverse-video t))
    (((class color) (background dark)) (:background "red" :foreground "black"))
    (((class color) (background light)) (:background "red" :foreground "black"))
    (t (:background "gray")))
  "Face for …
Run Code Online (Sandbox Code Playgroud)

emacs elisp

5
推荐指数
2
解决办法
1272
查看次数

在Mac上录制终端的脚本

script是记录终端所有活动的好工具(http://linuxers.org/article/script-command-line-tool-recordsave-your-terminal-activity).scriptMac上的内置可执行文件无法记录打字稿的时间.我正在尝试编译包util-linux(https://github.com/karelzak/util-linux,其中包含linux版本script),但没有成功:

$ make
make  all-recursive
Making all in po
make[2]: Nothing to be done for `all'.
  CC       lib/libcommon_la-strutils.lo
In file included from lib/strutils.c:16:
./include/strutils.h:77: error: conflicting types for 'strmode'
/usr/include/string.h:168: error: previous declaration of 'strmode' was here
lib/strutils.c:351: error: conflicting types for 'strmode'
/usr/include/string.h:168: error: previous declaration of 'strmode' was here
lib/strutils.c: In function 'size_to_human_string':
lib/strutils.c:442: warning: format '%jd' expects type 'intmax_t', but argument 8 has type 'uint64_t'
make[2]: *** [lib/libcommon_la-strutils.lo] …
Run Code Online (Sandbox Code Playgroud)

macos terminal

5
推荐指数
3
解决办法
3109
查看次数

如何在emacs lisp中打印特殊字符

例如,我的函数中的一行代码

 (message "char %c:%d" character count)
Run Code Online (Sandbox Code Playgroud)

将打印每个角色的计数.对于不可打印的字符,例如换行符和制表符,我希望输出看起来像:

 \n:4
 \t:6
Run Code Online (Sandbox Code Playgroud)

而不是字面上打印换行符和制表符.我怎样才能做到这一点?

emacs elisp

4
推荐指数
2
解决办法
655
查看次数

为什么在描述符类的__get__中需要“ if instance is None”?

我从有效的Python项目31中获得以下示例:

from weakref import WeakKeyDictionary
class Grade(object):
    def __init__(self):
        self._values = WeakKeyDictionary()
    def __get__(self, instance, instance_type):
        if instance is None: return self
        return self._values.get(instance, 0)

    def __set__(self, instance, value):
        if not (0 <= value <= 100):
            raise ValueError('Grade must be between 0 and 100')
        self._values[instance] = value


# Example 16
class Exam(object):
    math_grade = Grade()
    writing_grade = Grade()
    science_grade = Grade()

first_exam = Exam()
first_exam.writing_grade = 82
second_exam = Exam()
second_exam.writing_grade = 75
print('First ', first_exam.writing_grade, 'is right')
print('Second', second_exam.writing_grade, …
Run Code Online (Sandbox Code Playgroud)

python descriptor python-descriptors

4
推荐指数
1
解决办法
939
查看次数

如何使jupyter笔记本中的小部件可滚动?

出于某种原因,我希望我的 HTML 小部件具有固定的高度,无论小部件中有多少行。如果行太多而无法适应高度,理想情况下可以滚动查看所有行。我尝试了类似以下的方法,但它不起作用:

import ipywidgets as widgets
widgets.HTML(
    value="Hello <p>World</p><p>World</p><p>World</p><p>World</p><p>World</p><p>World</p><p>World</p><p>World</p>",
    placeholder='Some HTML',
    description='Some HTML',
    disabled=True,
    height='50px',
    overflow_y='scroll'
)
Run Code Online (Sandbox Code Playgroud)

ipython ipywidgets

4
推荐指数
1
解决办法
6986
查看次数